java-gobject-introspection r21 - trunk/src/org/gnome/gir/gobject
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r21 - trunk/src/org/gnome/gir/gobject
- Date: Wed, 3 Sep 2008 19:48:12 +0000 (UTC)
Author: walters
Date: Wed Sep 3 19:48:12 2008
New Revision: 21
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=21&view=rev
Log:
Keep a strong ref from Object to signal handlers, add weak ref to remove it
Modified:
trunk/src/org/gnome/gir/gobject/GClosure.java
trunk/src/org/gnome/gir/gobject/GObject.java
trunk/src/org/gnome/gir/gobject/GObjectAPI.java
Modified: trunk/src/org/gnome/gir/gobject/GClosure.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GClosure.java (original)
+++ trunk/src/org/gnome/gir/gobject/GClosure.java Wed Sep 3 19:48:12 2008
@@ -1,6 +1,7 @@
package org.gnome.gir.gobject;
-public class GClosure extends GBoxed {
+
+public abstract class GClosure extends GBoxed {
public GType getType() {
return GBoxedAPI.gboxed.g_closure_get_type();
}
Modified: trunk/src/org/gnome/gir/gobject/GObject.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GObject.java (original)
+++ trunk/src/org/gnome/gir/gobject/GObject.java Wed Sep 3 19:48:12 2008
@@ -53,6 +53,7 @@
import org.gnome.gir.gobject.GObjectAPI.GParamSpec;
import org.gnome.gir.gobject.GObjectAPI.GToggleNotify;
+import org.gnome.gir.gobject.GObjectAPI.GWeakNotify;
import com.sun.jna.Callback;
import com.sun.jna.NativeLong;
@@ -67,8 +68,15 @@
private final IntPtr objectID = new IntPtr(System.identityHashCode(this));
+ /* Hold a strong Java reference between this proxy object and any signal
+ * handlers installed. Often this would be done anyways, but if you're
+ * just calling System.out.println in a callback, it would otherwise
+ * be elgible for GC.
+ */
private Map<Long,Callback> signalHandlers = new HashMap<Long, Callback>();
+ private GWeakNotify weakNotify = null;
+
/**
* A tagging interface used in the code generator - if a method returns an interface,
* we have it extend this interface so we know it's a GObject.
@@ -76,14 +84,32 @@
*/
public static interface GObjectProxy {};
+ /**
+ * The core GObject initializer function, intended for invocation from
+ * return values of unmanaged code.
+ * @param init
+ */
public GObject(Initializer init) {
super(init.needRef ? initializer(init.ptr, false, init.ownsHandle) : init);
if (init.ownsHandle) {
strongReferences.put(this, Boolean.TRUE);
+ /* The toggle reference is our primary means of memory management between
+ * this Proxy object and the GObject.
+ */
GObjectAPI.gobj.g_object_add_toggle_ref(init.ptr, toggle, objectID);
if (!init.needRef) {
unref();
}
+
+ /* See the comment for signalHandlers */
+ weakNotify = new GWeakNotify() {
+ @Override
+ public void callback(Pointer data, Pointer obj) {
+ // Clear out the signal handler references
+ signalHandlers = null;
+ }
+ };
+ GObjectAPI.gobj.g_object_weak_ref(this, weakNotify, null);
}
}
Modified: trunk/src/org/gnome/gir/gobject/GObjectAPI.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GObjectAPI.java (original)
+++ trunk/src/org/gnome/gir/gobject/GObjectAPI.java Wed Sep 3 19:48:12 2008
@@ -84,10 +84,10 @@
void g_object_add_toggle_ref(Pointer object, GToggleNotify notify, IntPtr data);
void g_object_remove_toggle_ref(Pointer object, GToggleNotify notify, IntPtr data);
interface GWeakNotify extends Callback {
- void callback(IntPtr data, Pointer obj);
+ void callback(Pointer data, Pointer obj);
}
- void g_object_weak_ref(GObject object, GWeakNotify notify, IntPtr data);
- void g_object_weak_unref(GObject object, GWeakNotify notify, IntPtr data);
+ void g_object_weak_ref(GObject object, GWeakNotify notify, Pointer data);
+ void g_object_weak_unref(GObject object, GWeakNotify notify, Pointer data);
Pointer g_object_ref(GObject object);
void g_object_ref_sink(GObject object);
void g_object_unref(GObject object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]