prevent reference cycles between Java and native objects

This commit is contained in:
Julian Winkler
2024-07-26 21:47:08 +02:00
parent 45801d8f17
commit e3c0931714
30 changed files with 257 additions and 181 deletions

View File

@@ -1596,6 +1596,18 @@ public final class Bitmap {
}
}
@Override
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
super.finalize();
} finally {
if (!isRecycled()) {
recycle();
}
}
}
/**
* internal ATL method to create or get a GdkTexture for the pixbuf
* @return pointer to the GdkTexture

View File

@@ -19,6 +19,19 @@ public class Canvas {
this.widget = widget;
}
@Override
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
super.finalize();
} finally {
if (skia_canvas != 0) {
native_destroy_canvas(skia_canvas);
skia_canvas = 0;
}
}
}
// FIXME: are these _needed_ ?
public int save() {
@@ -444,4 +457,5 @@ public class Canvas {
private static native void native_rotate(long skia_canvas, long widget, float angle);
private static native void native_rotate_and_translate(long skia_canvas, long widget, float angle, float tx, float ty);
private static native void native_drawPath(long skia_canvas, long path, long skia_paint);
private static native void native_destroy_canvas(long skia_canvas);
}