GNOME Bugzilla – Bug 407591
TreeStore and ListStore do not allow inserted Objects to be garbage collected
Last modified: 2008-01-14 05:56:10 UTC
Please describe the problem: When new Objects are set into the above classes through setValue(), and either TreeStore.clear() or ListStore.clear() are called or references to those Stores are removed, the inserted Objects are not collected. Steps to reproduce: 1. Create a new TreeStore 2. Insert some Objects via setValue() 3. Try and free said Objects Actual results: Expected results: Does this happen every time? Other information: I'll submit a unit test shortly.
No doubt. java-gnome 2.x leaks like a rusty pail. (I was shocked to see all the stuff that isn't freed as I was looking through the bowels of that code 8-9 months ago. And, of course, there is the fundamental design problem that the prinicipal of encapsulation is not respected when it comes to its memory management approach) Look forward to your test case. AfC
Created attachment 82544 [details] Leaks memory through a TreeStore
I have been looking at the code for this bug. This code is creating a NewGlobalRef which is not being deleted anywhere: /* * Class: org.gnu.glib.Value * Method: g_value_set_java_object */ JNIEXPORT void JNICALL Java_org_gnu_glib_Value_g_1value_1set_1java_1object (JNIEnv *env, jclass cls, jobject value, jobject obj) { GValue *value_g; value_g = (GValue *)getPointerFromHandle(env, value); if ( G_VALUE_HOLDS_OBJECT(value_g) ) g_value_set_object (value_g, (gpointer)getPointerFromHandle(env, obj)); else if ( G_VALUE_HOLDS_POINTER(value_g) ) g_value_set_pointer (value_g, (*env)->NewGlobalRef(env, obj)); else if ( G_VALUE_HOLDS_BOXED(value_g) ) g_value_set_boxed (value_g, (gpointer)getPointerFromHandle(env, obj)); else g_value_set_pointer (value_g, (*env)->NewGlobalRef(env, obj)); } One solution is to store the Value object itself instead of the Java Object it encapsulates. And then decrement the GlobalRef when finialize of the Value object is called. We might require some magic to make sure that the finalize gets called :)... working on a patch.
*** Bug 410417 has been marked as a duplicate of this bug. ***
Incorrect dup bug number from bugsquad. AfC
Created attachment 83477 [details] [review] patch for glib-java
Created attachment 83478 [details] [review] patch for libgtk-java
the above patches fix the problem. The fix is split between glib-java and gtk-java. It was basically eliminaiting the NewGlobalRef call made in org_gnu_glib_Value.c and replacing it with proper NewGlobalRef/DeleteGlobalRef calls made org_gnu_gtk_TreeStore.c.
Was someone considering committing a patch for this? It doesn't really make a release in and of itself, but it might as well be in there, assuming reporter is happy it fixed the problem. AfC
The attached patches have worked well for me for a while... so it is good to go. I'll commit it and cloes the bug
I concur, the patches work great.
patch committed