Skip to content

Commit

Permalink
Fix behaviour of freeNatives()
Browse files Browse the repository at this point in the history
Summary:
@public

Prevents repeated deallocation of weak references.

Reviewed By: pasqualeanatriello

Differential Revision: D9131551

fbshipit-source-id: bc79596e056ae0657a55146ad786422fd0f5badc
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Aug 2, 2018
1 parent cdf9b84 commit b911848
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class YogaNodePropertiesByteBuffer implements YogaNodeProperties, Cloneab
private final long mNativePointer;
private boolean mHasBorderSet = false;
private boolean mHasNewLayout = true;
private boolean isFreed = false;

private static native ByteBuffer jni_getStyleBuffer(long nativePointer);

Expand All @@ -48,12 +49,10 @@ public YogaNodePropertiesByteBuffer(long nativePointer) {
mLayoutBuffer = jni_getLayoutBuffer(nativePointer).order(ByteOrder.LITTLE_ENDIAN);
}

private static native void jni_YGNodeFree(long nativePointer);

@Override
protected void finalize() throws Throwable {
try {
jni_YGNodeFree(getNativePointer());
freeNatives();
} finally {
super.finalize();
}
Expand Down Expand Up @@ -482,9 +481,14 @@ public YogaDirection getLayoutDirection() {
return YogaDirection.fromInt(getLayoutDirectionInt());
}

private static native void jni_YGNodeFree(long nativePointer);

@Override
public void freeNatives() {
jni_YGNodeFree(mNativePointer);
if (!isFreed) {
isFreed = true;
jni_YGNodeFree(mNativePointer);
}
}

private int getLayoutDirectionInt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ public YogaNodePropertiesJNI(YogaNode node, YogaConfig config) {
}
}

private native void jni_YGNodeFree(long nativePointer);
private static native void jni_YGNodeFree(long nativePointer);

@Override
public void freeNatives() {
jni_YGNodeFree(mNativePointer);
long nativePointer = mNativePointer;
mNativePointer = 0;
jni_YGNodeFree(nativePointer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ jlong jni_YGNodeCloneNoProps(
return jni_YGNodeClone(cls, nativePointer, clonedJavaObject, nullptr);
}

void jni_YGNodeFree(alias_ref<jobject> thiz, jlong nativePointer) {
void jni_YGNodeFree(alias_ref<jclass> thiz, jlong nativePointer) {
if (nativePointer == 0) {
return;
}
Expand Down

0 comments on commit b911848

Please sign in to comment.