| Author |
Approach to Garbage Collection Questions
|
Mallik Kumar
Greenhorn
Joined: Nov 26, 2011
Posts: 12
|
|
Hi folks, this is my first post. I have a problem dealing with GC questions.
I just wanted to know if there is an approach or a strategy to deal with these questions.
|
 |
Joseph Arnold
Ranch Hand
Joined: Oct 05, 2010
Posts: 42
|
|
|
Welcome to the ranch!! When you encounter a garbage collector question, write down the variable names referencing an object. For example, Object a = new Object(); 'a' contains the address of the new Object, depict this by writing a --> new Object. Now every time any other variable refers to the new Object, just write down that new variable name and connect it to the new Object using an arrow. Every time a variable is assigned to null, strike down that conncetion. Finally, when an object has no arrow pointing to it, then it is eligible for garbage collection. Well, it is simple and no great strateg but a sure shot method to get the correct answer!
|
 |
Mallik Kumar
Greenhorn
Joined: Nov 26, 2011
Posts: 12
|
|
|
Thanks a lot Arnold.
|
 |
Dennis Deems
Ranch Hand
Joined: Mar 12, 2011
Posts: 547
|
|
|
Draw a picture. Represent instantiated objects as circles, squares, blobs or whatever you like. Only something that can not possibly be confounded with a reference. Represent references with their names in the code. Keep your references and objects well segregated. The rest as Joseph recommends.
|
OCPJP 6
|
 |
Mallik Kumar
Greenhorn
Joined: Nov 26, 2011
Posts: 12
|
|
Could it be possible to explain the below problem with a diagram. I tried the above approach and it got a little confusing.
http://www.coderanch.com/t/564187/java-programmer-SCJP/certification/Garbage-Collection
|
 |
 |
|
|
subject: Approach to Garbage Collection Questions
|
|
|