Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions java/com/facebook/yoga/YogaConfigJNIFinalizer.java

This file was deleted.

30 changes: 30 additions & 0 deletions java/com/facebook/yoga/YogaConfigJNIFinalizer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.yoga

public class YogaConfigJNIFinalizer public constructor() : YogaConfigJNIBase() {

/*
* This is a valid use of finalize. No other mechanism is appropriate.
* YogaConfigJNIFinalizer exists specifically to release JNI-allocated native
* memory (via jni_YGConfigFreeJNI) when the Java object is garbage collected.
* This is the established pattern for JNI prevented leak classes in Yoga.
*/
@Throws(Throwable::class)
protected fun finalize() {
freeNatives()
}

public fun freeNatives() {
if (nativePointer != 0L) {
val pointer = nativePointer
nativePointer = 0
YogaNative.jni_YGConfigFreeJNI(pointer)
}
}
}
35 changes: 0 additions & 35 deletions java/com/facebook/yoga/YogaNodeJNIFinalizer.java

This file was deleted.

33 changes: 33 additions & 0 deletions java/com/facebook/yoga/YogaNodeJNIFinalizer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.yoga

public class YogaNodeJNIFinalizer : YogaNodeJNIBase {
public constructor() : super()

public constructor(config: YogaConfig) : super(config)

/*
* This is a valid use of finalize. No other mechanism is appropriate.
* YogaNodeJNIFinalizer exists specifically to release JNI-allocated native
* memory (via jni_YGNodeFinalizeJNI) when the Java object is garbage collected.
* This is the established pattern for JNI prevented leak classes in Yoga.
*/
@Throws(Throwable::class)
protected fun finalize() {
freeNatives()
}

public fun freeNatives() {
if (mNativePointer != 0L) {
val nativePointer = mNativePointer
mNativePointer = 0
YogaNative.jni_YGNodeFinalizeJNI(nativePointer)
}
}
}
Loading