#923 – An Object Isn’t Necessarily Deleted as Soon as It’s Dereferenced
September 4, 2013 2 Comments
The object won’t necessarily be deleted when you stop referencing it. The garbage collector will only delete the object when it needs to reclaim some space in memory. We refer to this as nondeterministic destruction–the idea that we can’t predict when an object will be destroyed.
// myDog references a Dog object Dog myDog = new Dog("Kirby"); // Set reference to null, so that we // no longer reference "Kirby" Dog object. myDog = null; // "Kirby" won't necessarily have been // destroyed at this point