Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection??

 
Joe Harry
Ranch Hand
Posts: 10085
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

The below statement is from here

Misconception Number One: A Reference to Oneself

One big misconception is that an object that maintains a reference to itself will not protect itself from being junked by the garbage collector. Some programmers place a reference to the object as a member variable, hoping that it will count. Let me assure you that it does not. Remember that an object already has an implicit reference to itself via the

this

keyword. Unless an object is referenced by other objects, which are in turn referenced, it does not satisfy the rule.

Guys can anyone help me to realize the above statement through code?? In particular I'm not able to follow the line in bold...Anyone please??
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One big misconception is that an object that maintains a reference to itself will not protect itself from being junked by the garbage collector.


I think that the not in this sentence should not be there.

Suppose you put your finger on your nose. That's not going to prevent you from being washed away if you fall into the river and are not tied to the riverside.
 
Joe Harry
Ranch Hand
Posts: 10085
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry, are they trying to say, an object which has reference to itself is Garbage Collected?? How can I realize this through code?? Can you please provide me with an example?
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose you put your finger on your nose. That's not going to prevent you from being washed away if you fall into the river and are not tied to the riverside.


Interesting...
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class has a member of the class's type that points to itself:


The objects of Ego are the noses, the ego variable is the finger.

Look at this self-reference as the smallest possible island of isolation.

On my system it prints three times "ouch" showing the ego objects are finalized.
(results of call to System.gc are system dependent)


Yours,
Bu.
[ December 18, 2006: Message edited by: Burkhard Hassel ]
 
Joe Harry
Ranch Hand
Posts: 10085
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bu for the code realization of the statement that I posted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic