Fixed a memory leak in the bundle cache implementation that was not
properly removing bundle archive objects from its internal array after
they were deleted.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@372507 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java
index 83cb1c9..c1568a6 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java
@@ -206,6 +206,18 @@
return null;
}
+ public int getArchiveIndex(BundleArchive ba)
+ {
+ for (int i = 0; i < m_archives.length; i++)
+ {
+ if (m_archives[i] == ba)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
public BundleArchive create(long id, String location, InputStream is)
throws Exception
{
@@ -257,6 +269,20 @@
public void remove(BundleArchive ba)
throws Exception
{
+ // Remove the archive itself.
((DefaultBundleArchive) ba).remove();
+ // Remove the archive from the cache.
+ int idx = getArchiveIndex(ba);
+ if (idx >= 0)
+ {
+ BundleArchive[] bas = new BundleArchive[m_archives.length - 1];
+ System.arraycopy(m_archives, 0, bas, 0, idx);
+ if (idx < bas.length)
+ {
+ System.arraycopy(m_archives, idx + 1, bas, idx,
+ bas.length - idx);
+ }
+ m_archives = bas;
+ }
}
-}
\ No newline at end of file
+}