This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Garbage Collection??

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bu for the code realization of the statement that I posted.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic