Skip to content

Commit cce4cf5

Browse files
Fix issue 176 - Promise change listener being garbage collected.
Keep GstCallback in field reference (which in turn holds reference to user supplied PROMISE_CHANGE listener). Both must live as long as Promise itself.
1 parent cc761ea commit cce4cf5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/org/freedesktop/gstreamer/Promise.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 Neil C Smith
2+
* Copyright (c) 2020 Neil C Smith
33
* Copyright (c) 2018 Vinicius Tona
44
* Copyright (c) 2018 Antonio Morales
55
*
@@ -38,6 +38,8 @@ public class Promise extends MiniObject {
3838

3939
public static final String GTYPE_NAME = "GstPromise";
4040

41+
private GstCallback changeFunction;
42+
4143
/**
4244
* Creates a new instance of Promise. This constructor is used internally.
4345
*
@@ -62,12 +64,17 @@ public Promise() {
6264
* {@link Promise} is changed
6365
*/
6466
public Promise(final PROMISE_CHANGE listener) {
65-
this(Natives.initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(new GstCallback() {
66-
@SuppressWarnings("unused")
67+
this(new GstCallback() {
6768
public void callback(Promise promise, Pointer userData) {
6869
listener.onChange(promise);
6970
}
70-
}, null, null)));
71+
});
72+
}
73+
74+
private Promise(GstCallback callback) {
75+
this(Natives.initializer(GSTPROMISE_API
76+
.ptr_gst_promise_new_with_change_func(callback, null, null)));
77+
this.changeFunction = callback;
7178
}
7279

7380
/**

0 commit comments

Comments
 (0)