This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 86625 - Memory leak using Utilities.activeReferenceQueue
Summary: Memory leak using Utilities.activeReferenceQueue
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords: PERFORMANCE
Depends on: 184192
Blocks:
  Show dependency tree
 
Reported: 2006-10-06 00:40 UTC by Jesse Glick
Modified: 2010-04-15 07:51 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2006-10-06 00:40:01 UTC
Some folks calling NB APIs from Ant tasks loaded using <taskdef> discovered that
they had memory leaks. If org-openide-util.jar is loaded in a special class
loader (such as the Ant class loader) and any code loaded in that loader uses
Utilities.activeReferenceQueue(), a thread is started which never dies for the
lifetime of the VM and holds onto Utilities.ActiveQueue.class and thus the whole
class loader. This happens even if all references sent to that queue have in
fact been collected and there are no more ever added.

Solution is to shut down the thread if as many references have been processed as
were originally enqueued. If more references come in later, can simply restart
the thread, though I don't imagine this would be common in practice.

Unfortunately we cannot check for certain how many references were enqueued, as
the Java API does not permit this. The API design of activeReferenceQueue() is
flawed. The ReferenceQueue itself should never have been exposed; should rather
have exposed e.g.:

public abstract ActiveReference<T> extends WeakReference<T> {
    protected ActiveReference(T object) {
        super(object, activeReferenceQueue);
    }
    protected abstract void disposed();
}

Instead, can just count how many times activeReferenceQueue() is called with
intent to enqueue a reference. OpenGrok confirms that all code in nb.org CVS in
fact does this in the expected way.

Wrote a test and do not see any harm from this patch, but would appreciate
review from Petr and/or Yarda as the logic is a bit subtle.
Comment 1 Jesse Glick 2006-10-06 00:43:41 UTC
Checking in src/org/openide/util/Utilities.java;
/shared/data/ccvs/repository/openide/util/src/org/openide/util/Utilities.java,v
 <--  Utilities.java
new revision: 1.23; previous revision: 1.22
done
Checking in test/unit/src/org/openide/util/UtilitiesActiveQueueTest.java;
/shared/data/ccvs/repository/openide/util/test/unit/src/org/openide/util/UtilitiesActiveQueueTest.java,v
 <--  UtilitiesActiveQueueTest.java
new revision: 1.3; previous revision: 1.2
done