Method org.jvnet.hk2.osgiadapter.HK2Main.HK2ServiceTrackerCustomizer#addingService(...) wraps a registered osgi service with an instance of AbstractActiveDescriptorand commits this descriptor into a global ServiceLocator.
When service is removed tracker attempts to remove descriptor from ServiceLocator using filter that checks equality of a removal candidate with a descriptor used to track service. (See HKMain.java#395)
This filter, however, will always return false, causing descriptor to be retained in a ServiceLocator preventing removed services (and so classloaders of uninstalled bundles) from being collected by GC.
The filter is checking an equality of its parameter with the service descriptor. Call to matches method in a ServiceLocatorImpl passes an instance of SystemDescriptor as a parameter (see ServiceLocatorImpl.java#L368). SystemDescriptor overrides equals method so that it returns false for objects that are not instances of SystemDescriptor (see SystemDescriptor.java#L929). But descriptor created in addingService method can not be instance of SystemDescriptor, since it is instance of AbstractActiveDescriptor.
Issue was reproduced on version 2.4.0 but still affects master, as far as I can tell.
Method
org.jvnet.hk2.osgiadapter.HK2Main.HK2ServiceTrackerCustomizer#addingService(...)
wraps a registered osgi service with an instance ofAbstractActiveDescriptor
and commits this descriptor into a global ServiceLocator.When service is removed tracker attempts to remove descriptor from ServiceLocator using filter that checks equality of a removal candidate with a descriptor used to track service. (See HKMain.java#395)
This filter, however, will always return false, causing descriptor to be retained in a ServiceLocator preventing removed services (and so classloaders of uninstalled bundles) from being collected by GC.
The filter is checking an equality of its parameter with the service descriptor. Call to matches method in a
ServiceLocatorImpl
passes an instance ofSystemDescriptor
as a parameter (see ServiceLocatorImpl.java#L368).SystemDescriptor
overrides equals method so that it returns false for objects that are not instances ofSystemDescriptor
(see SystemDescriptor.java#L929). But descriptor created inaddingService
method can not be instance ofSystemDescriptor
, since it is instance ofAbstractActiveDescriptor
.Issue was reproduced on version 2.4.0 but still affects master, as far as I can tell.