File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC question

 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question1: How many Object will be GCed after #1?
Question2: How many Objects will be Gced after #2
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, what do you think should be the answer? And why do you think so?
 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At #1 no object is eligible for GC. because, go() method has not finished and pudding object has also reference to this(which is new Mian at line 13).
At #2 two objects are eligible for GC. because, method is finished and there is no reference to pudding created at line 16 and also no reference variable to new Main() created at line 13.
Please correct me if I am wrong.
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds right to me.

Do you know the actual answer?
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at #1 as you said because
you are still inside go function.but as come out of go function the local variable which is declared inside this function(pudding) is no longer used .so it should
be GC.but here i have doubt in new Main() because you are creating an object but not assigning in any reference variable.but still jvm will have object for main.
so I think here when that obejct will be GC we cant say.corret me if somewhere i am wrong.
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
means gvm will check if that new Main() object is no longer used.it will be gc.
 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please someone clarify this. Thank you.
 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certpal question
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janki Shah wrote:At #1 no object is eligible for GC. because, go() method has not finished and pudding object has also reference to this(which is new Mian at line 13).
At #2 two objects are eligible for GC. because, method is finished and there is no reference to pudding created at line 16 and also no reference variable to new Main() created at line 13.
Please correct me if I am wrong.

You are right
 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic