Reputation: 5834
Let's say I created an big object in a scope. It is referred to by child scopes, but all of them exits gracefully. And no closure referring to it at all. After this scope exits, I suppose the last reference to the object is deleted, right? Is the memory consumed by the object freed right away, or is it only marked as free and has to wait for the garbage collector to delete it?
Upvotes: 1
Views: 228
Reputation: 22415
Garbage collection depends on the Javascript implementation. Theoretically, objects should be deleted after all references to them are gone. If you define an object in scope and nothing outside the scope references it (for example, adding it to an array outside the scope would be an outside reference), it should be collected sometime after you leave the scope.
This is a more detailed explanation.
Upvotes: 4