After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 407591 - TreeStore and ListStore do not allow inserted Objects to be garbage collected
TreeStore and ListStore do not allow inserted Objects to be garbage collected
Status: RESOLVED FIXED
Product: java-gnome
Classification: Bindings
Component: Obsolete
2.16.x
Other All
: Low normal
: ---
Assigned To: java-gnome bindings maintainers
java-gnome bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2007-02-13 19:57 UTC by Mike Cvet
Modified: 2008-01-14 05:56 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16


Attachments
Leaks memory through a TreeStore (1.22 KB, application/octet-stream)
2007-02-14 16:54 UTC, Mike Cvet
  Details
patch for glib-java (1.07 KB, patch)
2007-02-27 16:55 UTC, Sami Wagiaalla
none Details | Review
patch for libgtk-java (4.93 KB, patch)
2007-02-27 16:56 UTC, Sami Wagiaalla
none Details | Review

Description Mike Cvet 2007-02-13 19:57:24 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.
Comment 1 Andrew Cowie 2007-02-14 00:48:26 UTC
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
Comment 2 Mike Cvet 2007-02-14 16:54:24 UTC
Created attachment 82544 [details]
Leaks memory through a TreeStore
Comment 3 Sami Wagiaalla 2007-02-14 19:44:00 UTC
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.
Comment 4 Jens Granseuer 2007-02-21 15:28:26 UTC
*** Bug 410417 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Cowie 2007-02-22 22:00:48 UTC
Incorrect dup bug number from bugsquad.

AfC
Comment 6 Sami Wagiaalla 2007-02-27 16:55:39 UTC
Created attachment 83477 [details] [review]
patch for glib-java
Comment 7 Sami Wagiaalla 2007-02-27 16:56:20 UTC
Created attachment 83478 [details] [review]
patch for libgtk-java
Comment 8 Sami Wagiaalla 2007-02-27 16:58:41 UTC
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.
Comment 9 Andrew Cowie 2007-04-27 04:10:03 UTC
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
Comment 10 Sami Wagiaalla 2007-04-27 14:29:22 UTC
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
Comment 11 Mike Cvet 2007-04-27 14:33:18 UTC
I concur, the patches work great.
Comment 12 Sami Wagiaalla 2007-05-01 13:35:17 UTC
patch committed