File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes garbage collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "garbage collector" Watch "garbage collector" New topic
Author

garbage collector

rama rajesh
Greenhorn

Joined: Jun 22, 2010
Posts: 28

--> whenever the obj of type GC1 is destroyed,is the (string and GC2) of GC1 also destroyed?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

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.


JBoss In Action
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Jun 22, 2010
Posts: 28

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

Joined: Apr 16, 2008
Posts: 2187
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: garbage collector