• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

garbage collector

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

--> whenever the obj of type GC1 is destroyed,is the (string and GC2) of GC1 also destroyed?
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic