aspose file tools*
The moose likes Beginning Java and the fly likes how to identify whether an object is destroyed or not? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to identify whether an object is destroyed or not?" Watch "how to identify whether an object is destroyed or not?" New topic
Author

how to identify whether an object is destroyed or not?

Vs Raju
Greenhorn

Joined: Jun 29, 2011
Posts: 1

I'm new to java. Can anyone tell me how to identify whether an object is destroyed or not?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

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.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

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.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to identify whether an object is destroyed or not?