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.
activeReferenceQueue() has a problem described in issue #256943. I we provide an implementation of references instead of reference queue, we can have more control on it and we can provide implementation that does not need to access the ReferenceQueue internals and that does not suffer from the above problem.
Created attachment 157714 [details] The proposed CallbackReferences API
Please review the proposed API change.
Unfortunately, the first proposal has some problems. The use of finalizers is causing troubles, sometimes finalizers are called for objects (instances of Reference) which were placed into the ReferenceQueue and therefore callbacks were discarded before they should be executed. Also this proposal is increasing memory usage of these "active" callback references. I'm about to attach a significantly reworked proposal with additional tests.
Created attachment 157767 [details] New proposed CallbackReferences API I'm attaching the new proposal. Regarding naming, I was hesitating between CallbackReferences and ActiveReferences, if someone prefers a different name from the proposed one, it's easy to rename. There are two implementations of the background thread: 1. In NetBeans IDE, it's impossible to occur that at some point in time all callback references would be processed and the thread could be shut down. Therefore the extra memory usage caused by control references checking the GC, is just a waste of memory space. Therefore the IDE sets system property netbeans.CallbackReferences.delayShutdownOfCallbackThread=infinity which selects the indefinite background thread (old ActiveQueue) and adds no overhead with respect to the original implementation. 2. By default, to keep compatibility, a finishable background thread is used, but it adds an overhead of one extra weak reference having one int field. Tests are added.
Created attachment 157768 [details] Changed usages from old Utilities.activeReferenceQueue() to new CallbackReferences Usages changed throughout the NetBeans code base.
Since the usages of activeReferenceQueue() are spread throughout the NetBeans codebase, I'll wait with the integration until after all fixes for 8.1 patch 1 are done and merge into the fixes branch, in order not to complicate the backport.