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.
I'd like to subclass WeakListener for a listener interface used in the server registry so that I can take advantage of the existing infrastructure WeakListener has for polling. However, since I can't call setSource, or set the "source" field, the only time instances of my subclass will be removed after their referent is collected is when the event source actually generates an event. In the case of the server registry, this doesn't happen very often. If I could call setSource from my subclass, then the weak listeners could get collected more often.
API enhancements are generally not high priority and would not be considered for 3.2 except to fix critical bugs. Presumably you could copy the parts of WeakListener you need and do whatever you like. I am not even convinced there is a need for an enhancement at all; if you *know* when your listeners should be collected, then simply remove them as listeners from the source to begin with. WeakListener is only a convenience, so that you can attach listeners without having to worry about details of when to detach them. Perhaps in your case it is not appropriate to use it.
I don't have any problem with the lower priority, and, of course, I know I can copy what WeakListener does. I still think this is a necessary enhancement if you want others to use WeakListener. My understanding is that the purpose of WeakListener is make it so that objects are not held in memory just because they are listening for events on some other objects. Given the way Netbeans tries to free up nodes which aren't being displayed, WeakListeners seem like something most objects should be using. In my case, EJBs register with the server registry. As long as the EJB is active (i.e. displayed to the user) I want them to be registered with the server registry. When they aren't active, I want them to deregister. However, I don't know of a way to tell that an EJB is no longer being displayed (is there a way?), so I don't really know when to deregister. If I don't use a WeakListener (or my own version of weak listener), the EJB's registration in the server registry will keep the EJB in memory for the entire IDE session. In any case, the way WeakListener is implemented, when the polling cleanup routine is called, it calls the no argument version of removeListener(). This only removes the listener from the event source if the this.source field is set. As far as I can tell from reading the code, this.source is never set, so the no argument removeListener never does anything (am I missing something?). Instead, the only time the listener is every removed is when an event notification is done and the WeakListener.get method is called. This will do an actual remove. I understand that if I use WeakListener in its current state, it won't stop the EJBs from getting collected. It will however build up a large chain of WeakListener objects in the server registry. These may be small objects, but it seems like it would be good to get them cleaned up.
Someone more knowledgeable about how WeakListener works can answer the detailed questions at the end. In the meantime, I am assuming that your listeners are part of a Node or Children object? For Children objects, removeNotify() is the proper place to clean up listeners (if they are not weak anyway). I presume there is something similar for Node's but I am not sure (at worst, finalize()). Ales, I believe you are the right person for WeakListener, if not reassign...
Target milestone -> 3.3
Fixed in main trunk.
rev1.37
Resolved for 3.4.x or earlier, no new info since then -> closing.