Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

destroy objects

 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.gc();
System.runFinalization();
Cheers
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic