• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in GC.

 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prav sharma
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic