| Author |
Regarding Memory Leaks
|
sarma kiran
Ranch Hand
Joined: Jul 17, 2008
Posts: 30
|
|
Am going through the Memory Leaks Concept.
I have come across the below line.
"In Java typically memory leak occurs when an object of longer life cycle has a reference to objects of a short life
cycle."
Can any one explain with some example?
Thanks in advance..
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
Imagine you have a stack, implemented on an array. You can push objects onto the stack by sayingThen you pop things off the stack like thisThen you forget all about the f reference. But you have forgotten that it is still on that array. If you don't push anything else onto the stack, that f reference will stay there for ever. You have no methods allowing access to it, but the JVM still sees it as "reachable." If you find a copy of Joshua Bloch's Effective Java look on page 24 (2nd edition; don't know page for 1st edition) and it gives a much better explanation of the same problem.
|
 |
 |
|
|
subject: Regarding Memory Leaks
|
|
|