This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection." Watch "Garbage Collection." New topic
Author

Garbage Collection.

Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
G'day mates,

I am sitting for the SCJP1.4 exam in a few days time. I have been preparing for it for the past 2 months or so, and have been scoring consistantly around the 70-75% mark in all mock exams. (Hopefully I will pass the real exam, fingers crossed )

Anyway, I found that my main weakness lies in questions relating to garbage collection. Especially those that are in the format:

"How many objects are eligible for garbage collection immediately after line XXX? "

Can you please point me to the right direction where I can improve my knowledge in this area?

Thank you in advance
Mike Corleone


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

The Truth About Garbage Collection
Reference Objects and Garbage Collection
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
The second link has some good info.

Thanks champ!


Mike
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

You're very welcome. Best of luck on your exam!
Joseph Clark
Ranch Hand

Joined: Sep 10, 2005
Posts: 48
I have a less refined understanding of this problem.
Java uses reference semantics. Object references
act like pointers in C.

You create an object and object reference thusly:

SomeClass objectReference = new SomeClass();

You must be clear that objectReference is the
object reference that 'points' to the object
created with the *new* keyword.

Make an object:


Point a = new Point(1,1);

Make another reference:


Point b = a;


So:

------------------------------------
----a-----------------b----------------
-----\---------------/-----------------
------\-------------/------------------
------ \-----------/-------------------
-------___________------------------
------|-----(1,1)-----|-----------------
-------___________------------------
------------------------------------

Ahem.

You see Point a and Point b refer to the same object.
If:

b = new Point(2,3);

then:

------------------------------------
----a--------------------b----------------
-----\-------------------\---------------
------\-------------------\--------------
------ \-------------------\-------------
-------___________----__________----
------|-----(1,1)------|----|-------(2,3)-----|--
-------___________----___________---
------------------------------------
(These diagrams aren't working out well, but, perhaps
you see what I'm getting at)

And if:


a = b;


Then, the Point at (1,1) has no references referencing
it. Point at (1,1) becomes eligible for GC, but, there
is no telling when it will be garbage collected.

[ September 10, 2005: Message edited by: xxxx clark ]

[ September 10, 2005: Message edited by: xxxx clark ]

[ September 10, 2005: Message edited by: xxxx clark ]

[ September 10, 2005: Message edited by: xxxx clark ]

[ September 10, 2005: Message edited by: xxxx clark ]

[ September 10, 2005: Message edited by: xxxx clark ]
[ September 10, 2005: Message edited by: xxxx clark ]
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Mike the best explanation that I have seen till date is Corey's (See the link) Corey's GC Explanation

another thing that you can do is to search java ranch wherever Corey has answered GC questions .these discussions should clear your concepts.

Remember to sit with a pen and paper and learn the way Corey has taught to understand GC Questions.

Good Luck!!!
Shivani


/** Code speaks louder than words */
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection.
 
Similar Threads
Garbage collection questions
about Garbage collection
GC
How many object is eligible for garbage collection?
Help with Garbage Collection