diff --git a/java/com/facebook/csslayout/CSSNodeJNI.java b/java/com/facebook/csslayout/CSSNodeJNI.java index 3f770464..e4c30c95 100644 --- a/java/com/facebook/csslayout/CSSNodeJNI.java +++ b/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();