Community
Participate
Working Groups
My IInjector objects have a well-defined life-cycle. However, I noticed that I can't explicitly "dispose" an injector. Is it expected that the Garbage Collector cleans up the singletonCache? If yes I'm wondering if this is easy given the dynamics and the many references (injector, requestor, tracking, etc). Note, I'm using just the IInjector, not the full EclipseContext.
See also here: http://dev.eclipse.org/mhonarc/lists/e4-dev/msg05749.html
Yes, the intention is that GC clears singleton cache when injector is not needed anymore. If we cleared singleton cache how would we be able to ensure that those objects stay singletons? We do need to store them somewhere.
(In reply to comment #2) > Yes, the intention is that GC clears singleton cache when injector is not > needed anymore. How can I remove/dispose listeners that are no longer needed? At some point, I call IInjector#make. This creates an object that may have dynamic injected arguments (updated when they change). When the object is no longer needed, the code no longer references it. Assuming it will be garbage collected ... how do I then discover that I no longer need the listeners? Is that what IRequestor#isValid is for? If yes then this may lead to a situation where the listeners won't be removed when the system doesn't change and the listeners aren't triggered. I'm wondering if there is a better story for this. Any ideas? > If we cleared singleton cache how would we be able to ensure that those objects > stay singletons? We do need to store them somewhere. Agreed. A long as the injector is alive, it must not re-create singletons. I think what I really want is some way to dispose an injector. Which would also notify the object supplier in order to be able to unregister all listeners hooked into the system for dynamic updates.
(In reply to comment #3) > (In reply to comment #2) > > Yes, the intention is that GC clears singleton cache when injector is not > > needed anymore. > > How can I remove/dispose listeners that are no longer needed? At some point, I > call IInjector#make. This creates an object that may have dynamic injected > arguments (updated when they change). When the object is no longer needed, the > code no longer references it. Non-singleton object references are wrapped into WeakReference and should not prevent objects being garbage collected. > > Assuming it will be garbage collected ... how do I then discover that I no > longer need the listeners? Is that what IRequestor#isValid is for? If yes then > this may lead to a situation where the listeners won't be removed when the > system doesn't change and the listeners aren't triggered. I'm wondering if > there is a better story for this. Any ideas? Yes, you are right. If this becomes an issue we could add a "cleanup" task that cleans up lists of WeakReferences every now and then. There is also IInjector#uninject() which tells the system to forget about the object.
(In reply to comment #4) > Yes, you are right. If this becomes an issue we could add a "cleanup" task that > cleans up lists of WeakReferences every now and then. > > There is also IInjector#uninject() which tells the system to forget about the > object. Well, the issue I have is that my PrimaryObjectSupplier registers listeners in the system in order to update the requestor dynamically. However, there is no way to unregister those listeners or I haven't found it.