This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collector

 
rama rajesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

--> whenever the obj of type GC1 is destroyed,is the (string and GC2) of GC1 also destroyed?
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

Note that Java does funny things with strings, so while you have 10000 instances of String, there will only be one instance of the literal string "abcdefghijklmnopqrstuvwxyz", which is referenced by all 10000 String instances. And the literal string will never go away.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever the obj of type GC1 is destroyed,is the (string and GC2) of GC1 also destroyed?


If there are no active references to the GC2 instance, then it is "eligible for garbage collection." In regards to the String object (which is in the String literal pool), it may or may not be eligible for garbage collection depending upon the particular JRE implementation and its treatment of String objects in the literal pool.
 
rama rajesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whenever object is destroying, whatever the obj is having (insta varibales(objects),instance methods) will be destroyed. But if we are overwriting the finalize method,what kind of statements other than (system.out.println statements) can we write related to object?

Deallocation of memory for the obj will be handled by the garbage collector. what is the use of overriding the finalizing method. if use is there, give me an example of usage?




 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could certainly put any statement that you want in a Class finalize method. Why you would want to put anything here is questionable? If you have designed an application in such a way that this would be the best place to do something, then certainly go ahead and do it. However, there typically are many other design alternatives that may help you avoid depending upon the JREs garbage collection cycles or the finalize method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic