Examples: AndroidMath: Java9 compatibility fixed - finalizers can not be used.

git-svn-id: svn://ultimatepp.org/upp/trunk@16026 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
klugier 2021-07-19 20:56:16 +00:00
parent 181edf9277
commit e96f8d39c7
3 changed files with 12 additions and 9 deletions

View file

@ -58,6 +58,9 @@ public class AndroidMathActivity extends Activity
text += "Vec2: " + vec2.toString() + "\n";
tv.append(text);
vec1.dispose();
vec2.dispose();
}
static {

View file

@ -30,7 +30,7 @@ extern "C" {
mm.MakeCopy(env, jobjThis, jobjThat);
}
JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_nativeFinalize(
JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_nativeDispose(
JNIEnv *env,
jobject obj)
{

View file

@ -13,15 +13,15 @@ public class Vector
private long nativeAdress = 0;
/**
* We override finalize method, because we need to destroy native c++ object when
* there is not more reference to Java object. This method is called by default
* by garbage collector.
* In order to avoid memory leaks on the native side. The cleaning method needs to be
* called.
*
* In previous version of this example finalize method was used. However, in Java 9 the
* finalize method was deprecated and we can not longer relay on them.
*/
@Override
protected void finalize() throws Throwable
protected void dispose()
{
nativeFinalize();
super.finalize();
nativeDispose();
}
public Vector(int size)
@ -46,5 +46,5 @@ public class Vector
private native void construct(int size);
private native void copyConstruct(Vector vec);
private native void nativeFinalize();
private native void nativeDispose();
}