• Post Reply Bookmark Topic Watch Topic
  • New Topic

destroy objects  RSS feed

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finalize() is called by carbage collector after the object's destruction. How to force the object's destrution??? is there a method that destroys the object!!!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The finalize() method is called by the gc just BEFORE the objects destruction.
You can call System.runFinalization().
This topic was a discussion of this issue.
 
Rodney Woodruff
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finalize() is called before an object is finally destroyed.
There is no way to forcefully release all memory being held by the object (i.e. completely destroy an object). However, you can call System.runFinalization() and System.gc() to try to initiate object destruction.
You can also override the finalize method to make sure that an object properly closes or releases resources that it holds. One example of this would be to close a connection to a file that the object had open.
Keep in mind that finalize() is called by the JVM and you should avoid calling the method yourself. Instead call System.runFinalization() and System.gc() understanding that Garbage Collection may not happen exactly when you call it.
My question to you is what would you like to do that the JVM can't do as it relates to destroying an object?
[ December 18, 2002: Message edited by: Rodney Woodruff ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.gc();
System.runFinalization();
Cheers
 
pradeepbill arumalla
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the finalize() method is called before the object is garbage collected
no,there is no way to force fully destroy an object...this process of destruction is in the hands of Garbage Collector
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can also override the finalize method to make sure that an object properly closes or releases resources that it holds. One example of this would be to close a connection to a file that the object had open.
[/QB]

You can do a lot of things.
Close a connection to a file when you finished reading/ writing.
As an BAD example you CAN close it by finalize, but you shouldn't.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!