gBroutin / gstreamer-java

Automatically exported from code.google.com/p/gstreamer-java
0 stars 0 forks source link

Gobject Possible memory leak #93

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi guys

From analysing various java heap dumps, I have a lot of references, that are 
being held onto because of the strongReferences map in gobject.

I have updated the disposeNativeHandle() in gobject to look like

   protected void disposeNativeHandle(Pointer ptr) {
        logger.log(LIFECYCLE, "Removing toggle ref " +
getClass().getSimpleName() + " (" + ptr + ")");
        GOBJECT_API.g_object_remove_toggle_ref(ptr, toggle, objectID);
        strongReferences.remove(this);
    }

Basically added a strongReferences remove. Now when I
call dispose(), references of objects inherited from Gobject are now
cleaned up properly.

1) do you see any problem with this change? Functionally I see no
adverse effect, and i see far smaller java heaps.
2) im a bit concerned there are other issues in here, where we are not
gc'ing all the objects.

Can we get the strongReferences.remove(this); added into the 
disposeNativeHandle function in the server.

Original issue reported on code.google.com by ch...@crazyfool.org on 21 Dec 2011 at 5:32

GoogleCodeExporter commented 8 years ago
i ask our expert and it's not that easy.
the most important part is the gobject_remove_toogle_ref which decrements the 
refcount. just because you thing there is no more reference doesn't mean there 
is not any reference in the underlying C layer which means the C objects will 
never be disposed! you can print the value of the toogle_ref when you assume 
it's 0 and if it's not 0 you'd debug which hold the remaining references...

Original comment by lfar...@lfarkas.org on 22 Dec 2011 at 11:11

GoogleCodeExporter commented 8 years ago
Hi

Surely this is only true if 1 native object points to multiple gobjects ? Is 
this the case? If not then when we dispose of the Native handle we should be 
removing this StrongReference entry. If we dont remove this map entry then we 
prevent garbage collection in the JAVA side. 

Original comment by ch...@crazyfool.org on 3 Jan 2012 at 1:07

GoogleCodeExporter commented 8 years ago
it seems you assume we never remove the element. in the 
GOBJECT_API.g_object_remove_toggle_ref(ptr, toggle, objectID) the toogle 
parameter is a callback. this tell whether it's the last reference or not. if 
yes we remove from the strongReferences so won't be any reference in java.
http://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#g-ob
ject-remove-toggle-ref

Original comment by lfar...@lfarkas.org on 4 Jan 2012 at 1:07

GoogleCodeExporter commented 8 years ago
if you still believe you find a bug please reopen it. the best would be a 
simple example java code...

Original comment by lfar...@lfarkas.org on 4 Jan 2012 at 2:06