Forums Register Login

Doubt in GC.

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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 .
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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

 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 942 times.
Similar Threads
Vector
Can I clone my class like this?
Vector
Any benefit by using StringBuffer like this?
Sets (Universal, Subsets, Union)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:56:53.