• 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

GC

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. This statement is true.
regds
maha anna
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dadi:
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


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;

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
regds
maha anna

[This message has been edited by maha anna (edited March 10, 2000).]
 
Rolf Weasel
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic