Fixed a bug where the service registry was holding a reference to a bundle
after it has released all of its used services; this was inhibiting garbage
collection.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@468401 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
index d5b9716..c0fe131 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
@@ -281,7 +281,18 @@
// bundle.
if (usage.m_count == 0)
{
- m_inUseMap.put(bundle, removeUsageCount(usages, ref));
+ // Remove reference from usages array.
+ usages = removeUsageCount(usages, ref);
+ // If there are no more usages in the array, then remove
+ // the bundle from the inUseMap to allow for garbage collection.
+ if (usages.length == 0)
+ {
+ m_inUseMap.remove(bundle);
+ }
+ else
+ {
+ m_inUseMap.put(bundle, usages);
+ }
ServiceRegistrationImpl reg =
((ServiceReferenceImpl) ref).getServiceRegistration();
reg.ungetService(bundle, usage.m_svcObj);