This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
Joined: Jun 22, 2010
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?
Joined: Apr 16, 2008
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.