aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help with Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help with Garbage Collection" Watch "Help with Garbage Collection" New topic
Author

Help with Garbage Collection

Timothy Stone
Ranch Hand

Joined: Aug 01, 2001
Posts: 71
I have taken the exam once... it's as tough as they say and will be taking it again soon.
I'm a little upset that I missed the one garbage collection question! The topic is glossed over by many study guides, and the question on the exam is certainly tougher than "Can you force garbage collection?" (as many are led to believe will be the extent of coverage on the exam).
Does anyone have some good examples, or "mock" exam questions, on the subject of garbage collection?
Thanks,
Tim
------------------
--
"This Satan's drink [coffee] is so delicious,
we shall cheat Satan and baptize it."
Pope Clement the VIII (1592-1605)


Timothy Stone, MIT, SCJP
http://www.petmystone.com/
"This Satan's drink [coffee] is so delicious, we shall cheat Satan and baptize it." --Pope Clement the VIII (1592-1605)
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Timothy!
I got passed the exam but on this area I got nothing. I GUESS there is no more than one question of this area at the exam, but still I managed to score the total of zero points on gc and got eaten, real good
This is what I know from the subject:
1) gc exists
2) there is no control over point of gc execution
3) one can handle leaks through gc although
4) gc is good (refer #3 and related)
------------------
Antti Barck
It Solutions Consultant -- NSD Oy
(SCJP pending)

[This message has been edited by Antti Barck (edited August 06, 2001).]
Snylt Master
Ranch Hand

Joined: Jul 07, 2001
Posts: 55
Hi! Have you read A programmers guide to Java certification?
Chapter 8 covers object lifetime/ garbage collection!
I understand if you failed the question on garbage collection. It's a difficult task. At least I think so.
Altso try too search javaranch for garabage collection.

Preparing for the Java 2 Certification exam
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by Snylt Master:
Hi! Have you read A programmers guide to Java certification?
Chapter 8 covers object lifetime/ garbage collection!
I understand if you failed the question on garbage collection. It's a difficult task. At least I think so.
Altso try too search javaranch for garabage collection.

As I have C/C++ background an I can appreciate this feature of Java a lot - with gc you dont have to do nothing else but set evrything you used to nothing!
------------------
Antti Barck
It Solutions Consultant -- NSD Oy
(SCJP pending)

[This message has been edited by Antti Barck (edited August 06, 2001).]
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi guys,
The key to understanding gc is, IMHO, understanding
1. how scope is determined (JLS §6.3)
2. how object reference variables are passed in methods (see Article on parameter passing
If you have a solid grasp of the above you'll be able to sort out whether or not a particular object is eligible for gc.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have always realized the scope, but still I got zero outta gc.
I am not sure whether it is fertile to go much beyond the fact that you should just remember to refer evrything to null after you have done w/ 'em.
(you dont have to believe me as I got zero outta gc)
------------------
Antti Barck
It Solutions Consultant -- NSD Oy
(SCJP pending)
[This message has been edited by Antti Barck (edited August 06, 2001).]
Timothy Stone
Ranch Hand

Joined: Aug 01, 2001
Posts: 71
Thanks for the replies... but I will expand on some of them, hopefully, sparking that flame that helps me get the question right next time...
Marcus Green notes in his tutorial regarding GC:
Local variables in methods go out of scope when the method exits. At this point the methods are eligible for garbage collection. Each time the method comes into scope the local variables are re-created.

It was this sort of problem with understanding scope that burned me on the exam the first time.
Jane makes a note about reference variables passed to methods and notes the importance of scope.
If a method is returning a value as it exits v. ( as noted by MG ) the method exiting directly , is that local variable available for collection?
Thanks for the help.
------------------

"This Satan's drink [coffee] is so delicious,
we shall cheat Satan and baptize it."
Pope Clement the VIII (1592-1605)
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Timothy,
If the local variable is returned to the calling method then the object it referenced will have a new reference.
The reference variable will cease to exist when the method ends BUT the object it referenced will not be eligibile for gc.
Here's a quick example:

'bool' is a local variable which points to a newly created Boolean object. The reference to this object is returned by the method so that the reference variable 'b' in 'main' now points to the new Boolean object.
As the object still has a reference it is not eligible for gc even though the method has finished executing.
Hope that is clearer.
Guess I should amend my post to include returned values
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with Garbage Collection