posted 23 years ago
Hi everyone!
My doubt is from R&H page.22 in which he explains Leaks in Garbage collection System.
His description is as follows
I this example, assume the array "Stroage" is being used to maintain the storage of a stack. This pop() method is inappropriate:
1. public Object pop(){
2 return storage[index--];
3. }
If the caller of this pop() method abandons the popped value, it will not be eligivle for garbage collection until the array element containing a reference to it is overwritten. This might take a long time. You can speed up the process like this:
1. public Object pop(){
2 Object returnValue = storage[index];
3 storage[index--] = null;
4. return returnvalue;
5 }
The concept of what he is trying to tell is not getting to me. First I didn't get what he means
by saying "method abandons popped value" then the sentence "array element containing a reference
to it is overwritten"
Can somebody explain be elaborately of what is happening above.
Regards
Ajay.