About Question com.enthuware.ets.scjp.v6.1.799 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.1.799 :

Post by ETS User »

Thus, in the next GC cycle when the GC tries to reclaim the memory of FinalizeTest object, it sees that it has a valid reference and this ignores the object.
Is this really true for all VMs using any GC-algorithm?

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.1.799 :

Post by admin »

If there is a live reference to any object, the GC will not destroy that object. This is guaranteed to be true for any GC algorithm. So if you were to create such a reference in finalize method, the object will not be destroyed.

HTH,
Paul.

normc
Posts: 5
Joined: Thu Apr 19, 2012 2:18 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.1.799 :

Post by normc »

My interpretation was that it will be eligible for GC because even though the List contains a reference, and FinalizeTest has a reference to Resurrecter, nothing points to FinalizeTest, so its composite objects are eligible for GC.

From Mughal, p391: "...we can conclude that if a composite object becomes unreachable, its constituent objects also become unreachable, barring any reachable references to the constituent objects."

However, I do see that there are pointers to FinalizeTest in the List. Is this not a similar situation where 2 objects that point to each other are eligible for GC?

Pegazz

Re: About Question com.enthuware.ets.scjp.v6.1.799 :

Post by Pegazz »

The difference is that in this case the list is static.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests