From 08e715bc9c8346764b8bf025869ee4412de1ff43 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Tue, 11 Oct 2016 04:48:47 -0700 Subject: [PATCH] Add finalizer to release any unreleased native memory Reviewed By: lucasr Differential Revision: D3992759 fbshipit-source-id: f648b72ead5bdb7257a5197496b19795f71f3788 --- .../java/com/facebook/csslayout/CSSNodeJNI.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeJNI.java b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeJNI.java index 3f7704647..e4c30c95f 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeJNI.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeJNI.java @@ -60,6 +60,10 @@ public class CSSNodeJNI implements CSSNodeAPI { throw new IllegalStateException("You should not reset an attached CSSNode"); } + free(); + } + + private void free() { jni_CSSNodeFree(mNativePointer); mNativePointer = 0; mChildren = null; @@ -67,6 +71,17 @@ public class CSSNodeJNI implements CSSNodeAPI { mMeasureFunction = null; } + @Override + protected void finalize() throws Throwable { + try { + if (mNativePointer != 0) { + free(); + } + } finally { + super.finalize(); + } + } + @Override public int getChildCount() { return mChildren.size();