Sixth elimination of expired references
There will still be memory leak in Java, such as a stack growth and contraction, then the object pops from the stack will not be garbage collected, the immediate use of the stack of the program no longer reference these objects. This is because the inside of the stack maintains outdated references to these objects (which are never dismissed) and needs to be shown to empty (null) the objects and tell the garbage collector to reclaim them.
For example, in the implementation of the Stack class, the pop () function will eventually have null operations on the element:
Public synchronizede pop () {e obj; intLen =size (); Obj=Peek (); Removeelementat (Len-1); returnobj; } Public synchronized voidRemoveelementat (intindex) {... .. ........... elementdata[elementcount]=NULL;/*To-let GC do it work*/ }
In addition to the memory leaks on the stack, there is a memory leak on the cache, that is, putting the object in the cache and forgetting it, as well as listeners and other callbacks, this looks less serious ....
[Effective Java Reading notes] Chapter II Creating and destroying objects sixth-? Reviews