Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313225 - Don't over use finalize()
Summary: Don't over use finalize()
Status: RESOLVED WORKSFORME
Alias: None
Product: WTP Java EE Tools
Classification: WebTools
Component: jst.j2ee (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Jason Sholl CLA
QA Contact: Chuck Bridgham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 15:16 EDT by Gary Karasiuk CLA
Modified: 2010-05-18 11:00 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Karasiuk CLA 2010-05-17 15:16:03 EDT
Using the finalize() method can slow down GC and cause other memory problems. It should only be used as a last resort. 

Please remove the finalize() method from
org.eclipse.jst.jee.archive.internal.ArchiveImpl

Writing something to stderr does not seem like a strong enough reason to have this method.
Comment 1 Gary Karasiuk CLA 2010-05-17 15:22:19 EDT
I just noticed there is a close() in the finalize methods as well, so it is not quite a bad as I first thought.

Please review if this is still needed, because relying on finalize to close your archive is not recommended.
Comment 2 Rob Stryker CLA 2010-05-18 04:15:49 EDT
seems like something Jason would know about
Comment 3 Jason Sholl CLA 2010-05-18 09:52:34 EDT
This is working as designed.  The finalize() method was put in place in order to help facilitate proper usage of the IArchive API.  Too often developers using the API forget to follow this pattern and fail to close the archive.

IArchive archive
try{
  archive = //open the archive
} finally{
  if(archive != null) archive.close();
}

This leads to open file handles which then require the entire workbench to be brought down in order to release the file handles.  The finalize() method was put in place to do two things; 1. warn the developers with the exception to stderr that they forgot to close the archive, and 2. close the archive if it was orphaned.  These precautions have helped track down many bugs, and unless there is another ensure archives are closed and developers are sternly reminded to close them, the finalize() method should remain.
Comment 4 Gary Karasiuk CLA 2010-05-18 11:00:52 EDT
(In reply to comment #3)
Why does it write to syserr instead of a log?