• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with Garbage Collection

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic