I have done some research on the java garbage collector and understand that an object who is no longer referenced will/should be handled by the garbage collector. In terms of arrays-of-objects, I am aware that assigning a new object to a location in the array does not properly deallocate the previously allocated object.
- I would like to know how to remove and properly deallocate an object from an array at location x and assign a new object to the same array at location x.
- I would also like to know how to properly deallocate the array itself.
Setting an object in an array to
nullor to another objects makes it eligible for garbage collection, assuming that there are no references to the same object stored anywhere.So if you have
The garbage collection rarely will reclaim memory of locals though, so garbage collection will mostly happen already outside of the scope of the function.