Add finalizer to release any unreleased native memory
Summary: Ensure all native memory is released once gc deallocates the java object reference. Reviewed By: lucasr Differential Revision: D3992759 fbshipit-source-id: f648b72ead5bdb7257a5197496b19795f71f3788
This commit is contained in:
committed by
Facebook Github Bot
parent
d506e6ab94
commit
f61fbd269e
@@ -60,6 +60,10 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
|
||||
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<CSSNodeJNI> {
|
||||
mMeasureFunction = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (mNativePointer != 0) {
|
||||
free();
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildCount() {
|
||||
return mChildren.size();
|
||||
|
Reference in New Issue
Block a user