diff --git a/examples/AndroidMath/AndroidMathActivity.java b/examples/AndroidMath/AndroidMathActivity.java index 68974724b..6bfc3fdec 100644 --- a/examples/AndroidMath/AndroidMathActivity.java +++ b/examples/AndroidMath/AndroidMathActivity.java @@ -58,6 +58,9 @@ public class AndroidMathActivity extends Activity text += "Vec2: " + vec2.toString() + "\n"; tv.append(text); + + vec1.dispose(); + vec2.dispose(); } static { diff --git a/examples/AndroidMath/Vector.cpp b/examples/AndroidMath/Vector.cpp index 15e1ac392..7ec89562f 100644 --- a/examples/AndroidMath/Vector.cpp +++ b/examples/AndroidMath/Vector.cpp @@ -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) { diff --git a/examples/AndroidMath/Vector.java b/examples/AndroidMath/Vector.java index 246243bfc..79fce6ada 100644 --- a/examples/AndroidMath/Vector.java +++ b/examples/AndroidMath/Vector.java @@ -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(); }