Skip to content

Commit 5e48302

Browse files
committed
runtime: fix memory leak on release objects
When a java object is finally freed in Java, we notify the JS side to free the JS counterpart. At this time, the Java object is held weakly in Java too using a WeakReference. While the Java object is weakly held, the WeakReference is strongly kept in a HashMap never getting removed. In this PR we release the WeakReferences too on GC event ensuring that all memory is reclaimed.
1 parent 22fd3b1 commit 5e48302

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

test-app/runtime/src/main/java/com/tns/Runtime.java

+3
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,9 @@ public void notifyGc() {
764764
}
765765

766766
public void notifyGc(int[] objectIds) {
767+
for (int id: objectIds) {
768+
weakInstances.remove(id);
769+
}
767770
notifyGc(runtimeId, objectIds);
768771
}
769772

0 commit comments

Comments
 (0)