This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
For SCJP what topics do we have to cover regarding Garbage Collection .....also I cudnt understand this code given in RHE under the topic Causing leaks to a Garbage Collection System ....can ayone please explain... the Code goes:
if you don't do that(set the storage[index--] to null), the values you returned before are still in the storage,right? that will cause the leak of the memory. [ April 09, 2002: Message edited by: andy lau ]
SMalik, Welcome to Javaranch I'd like you to read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you. [ April 12, 2002: Message edited by: Valentin Crettaz ]
Well, I wouldn't really call this a memory leak. To me, its more of a memory optimization. If you think about it, if it is an array of objects, then it has a predetermined size. So the array is already set to the total it can possibly hold. It won't be leaking memory, it will just be holding memory that it doesnt need, but you've already set the array to a desired max size, so you'll never get over your predetermined size.
I am sorry Joshua, I'm with Andy. Note that the array is not local. Thus when the returned object looses its references it is still holded by the array and it can not be garbage collected.
SCJP2. Please Indent your code using UBB Code
Joined: Nov 22, 2008
yeah thanx guys.....n Val I guess now my name's fine ...
Joined: Mar 14, 2002
I understand that Jose.. but I just wouldnt call it a memory leak.. Let me try to explain what I was trying to say ..Lets say we have an array that we know will at most hold 20 objects.. So we set it to 20 objects. Now, we know that sometimes it may hold 20 objects.. so we plan for it. We will never go over our planned 20 object size, even if we don't set the objects to null. So, to me, its not really a memory leak, its just not optimized. I think of a memory leak as causing us to use more memory than we planned to use. In this case, we arent, because we planned for 20 objects, if we use them or not is not the issue. I might even run faster without the necessary null calls