Author | Topic: GC |
Dadi greenhorn |
posted March 10, 2000 03:16 PM
Can anybody confirm whether the following stament is true on GC. I think it is true. - The programmer can signify through a reference that an object is no longer needed - True/False
|
maha anna bartender |
posted March 10, 2000 03:18 PM
Yes. This statement is true. regds maha anna
|
Jane Rozen ranch hand |
posted March 10, 2000 03:32 PM
quote: Sure. If you want to tell the system that you done with the object, all you have to do is to remove all references to it like this: myObj=null;
|
Rolf Weasel ranch hand |
posted March 10, 2000 05:01 PM
I think the answer is false since an object can have more than one reference. Hence, one reference cannot always determine the fate of an object.
|
maha anna bartender |
posted March 10, 2000 05:26 PM
The programmer can signify through a reference that an object is no longer needed - True/False If you just see the vanilla meaning of this statement it is true. A programmer can give a green signal to the GC to reclaim the memory by setting the object's reference to null. If you purposly keep one more reference to the object and then set one ref to null means, you are cheating yourself. You are responsible for that. Sometimes without the programmer's knowledge there may be another ref kept to the object. For example, when you pass a ref to a method (which is written by someone else and you don't have the source code) you CAN NOT be sure, after that method invocation, whether there is one more ref added to this input ref during the method execution. The wish of setting an object's reference to null is as though saying that 'as far as I am concerned I do not need this object anymore' and you are signifying the GC to collect the memory of that object. Checking if there is one more ref to this object and claiming the memory back (if at all GC tries to collect this object) is upto to the GC mechanism. [This message has been edited by maha anna (edited March 10, 2000).]
|
Rolf Weasel ranch hand |
posted March 10, 2000 08:20 PM
The programmer can signify through a reference that an object is no longer needed - True/False The statement implies that given a reference, u can signify that the object is no longer needed. That's why i feel it should be false. I guess it's dubious English syntax.
|
| | |