my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in GC. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in GC." Watch "Doubt in GC." New topic
Author

Doubt in GC.

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
I was just trying out codes on GC, I made this example on my own with some help from K &B.



Here when line1 is invoked the object referenced by mc will be available for GC. This happens beacuse once a method completes the references to the object dissappear with the call stack.
But just to assume that was not the case. Then even if mc = null is invoked, the object wont be available for GC as it still has references from the code inside the method, Am i right?
Prav sharma
Ranch Hand

Joined: Feb 07, 2005
Posts: 102
Abhi vijay wrote:I was just trying out codes on GC, I made this example on my own with some help from K &B.



Here when line1 is invoked the object referenced by mc will be available for GC. This happens beacuse once a method completes the references to the object dissappear with the call stack.
But just to assume that was not the case. Then even if mc = null is invoked, the object wont be available for GC as it still has references from the code inside the method, Am i right?


Is this code really working???


mc1=doStuff2(mc);

whereas the method signature is having return type as VOID .
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

But just to assume that was not the case. Then even if mc = null is invoked, the object wont be available for GC as it still has references from the code inside the method, Am i right?


you are right here.the object wont be avaiable for GC, assumimg the references from the method still exists. BUT it wont happen.Because the local reference are ALWAYS unreachable once the method returns.


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Prav sharma
Ranch Hand

Joined: Feb 07, 2005
Posts: 102
James Tharakan wrote:
But just to assume that was not the case. Then even if mc = null is invoked, the object wont be available for GC as it still has references from the code inside the method, Am i right?


you are right here.the object wont be avaiable for GC, assumimg the references from the method still exists. BUT it wont happen.Because the local reference are ALWAYS unreachable once the method returns.


james,

what about this part

mc1=doStuff2(mc);

whereas the method signature is having return type as VOID in the code.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

mc1=dostuff(mc);
I understand that.... the compiler would not allow that...
I was talking about the situation where in the references of the method is NOT YET destoryed.
I was thinking so because Abhi told,
But just to assume that was not the case
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in GC.