Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to identify whether an object is destroyed or not?

 
Vs Raju
Greenhorn
Posts: 1
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to java. Can anyone tell me how to identify whether an object is destroyed or not?
 
Stephan van Hulst
Bartender
Pie
Posts: 5813
61
  • Mark post as helpful
  • send pies
  • 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.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic