Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection.

 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second link has some good info.

Thanks champ!


Mike
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome. Best of luck on your exam!
 
Joseph Clark
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic