The Artima Developer Community
Sponsored Link

Compared to destruction in C++

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Compared to destruction in C++

Posted by Alex Chan on 15 Dec 1998, 6:14 AM

The trick to release non-memory resources in a destructor in C++
seems not to apply anymore in Java, because garbage collection
and finalization is not as controlled. Do you agree? Of course,
may be someone could argue that it has never been an excellent
idea in C++ to do so, but it is cleaner because C++ does not
have a finally clause.

Given the behavior in Java, we almost always have to provide a
seperate method to release resources, and make sure that the
method is called at the right time instead of relying on the
finalizer to do so.

It also seems that we almost always want to call System.runFinalizersOnExit(true) such that objects will be guaranteed to be finalized no matter how the program
ends. Am I right?




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us