• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to identify whether an object is destroyed or not?

 
Greenhorn
Posts: 1
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to java. Can anyone tell me how to identify whether an object is destroyed or not?
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on your definition of "destroyed". If you mean complete reclamation by the JVM, consider making a PhantomReference to the object.

And welcome to CodeRanch. Please check your private messages for an administrative matter.
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

danger boy wrote:I'm new to java. Can anyone tell me how to identify whether an object is destroyed or not?



Greetings and welcome to JavaRanch.

What do you mean by destroyed? Normally, we leave it to the garbage collector to clean out the memory. There are no command opposite to new that you can use to get an object removed. A commonly used technique is to set the reference to an object to null to signal to the GC that "the item I was pointing to is now not important to me". So "dealloc" does not exist.
 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you still have a reference to it, it still exists. Objects get garbage collected some unspecified time after they go out of scope, but it's not something you have to worry about in Java.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic