When an array of objects is not referenced anymore, does the objects in that array are garbage collected too? (assuming no variables are referencing the elements)
In this page, http://java.sys-con.com/node/37613
it says –
“The biggest danger is placing an object into a collection and forgetting to remove it. The memory used by that object will never be reclaimed.”
If you make sure to nullify the references, why will that memory be unclaimed?
Thanks
Yes.
This is when you are holding a reference to the collection. For example, if you have a
Mapin which you put a key-value and then forget to remove then it stays there for ever. Think http sessions, if you use something inServerContextor some such at start of request using session id as key but fail to remove it at end of the request processing..