fix reference counting for GtkWidgets created from java

GtkWidgets extend GInitiallyUnowned and are automatically freed when
removing from parent widget. We need to add an extra reference, to make
sure the object keeps alive as long as the java widget has a reference
to it
This commit is contained in:
Julian Winkler
2023-08-22 13:49:09 +02:00
parent faf4a3281e
commit 36b6132324
12 changed files with 36 additions and 11 deletions

View File

@@ -775,7 +775,9 @@ public class View extends Object {
public static HashMap<Integer, View> view_by_id = new HashMap<Integer, View>();
public View() {} // FIXME
public View() {
this(Context.this_application);
} // FIXME
public View(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@@ -843,6 +845,7 @@ public class View extends Object {
protected native long native_constructor(Context context, AttributeSet attrs); // will create a custom GtkWidget with a custom drawing function
private native void native_set_size_request(int width, int height);
protected native void native_destructor(long widget);
// --- stubs
@@ -1052,4 +1055,13 @@ public class View extends Object {
public int getVisibility() {return View.VISIBLE;}
public boolean isInEditMode() {return false;}
@Override
protected void finalize() throws Throwable {
try {
native_destructor(widget);
} finally {
super.finalize();
}
}
}