You can create new objects, but when you've finished using them there's no real way to destroy them immediately as well?
Why didn't every OOP runtime implement such behaviour?
I'm sure we as developers could (often) organize for object instances to be destroyed when we've finished using them.
function work(){
var p1:Point = new Point(x, y);
var p2:Point = new Point(x2, y2);
....
destroy p1;
destroy p2;
}
Speaking from .NET, the answer is memory safety.
Consider two items A and B (objects or methods) both holding a reference to Object X.
And now A does a destroy X;
. B is then left with an invalid reference. This is a common error pattern in unmanaged languages. Removing manual destruction prevents this.
But an equally important issue is: Would it help much? The answer is no. Short lived memory is very cheap in .NET. The destroy as you propose it would not be of any value.