Re: memory management with glibmm & giomm



On Tue, 2008-10-14 at 22:37 +0200, nico wrote:
> > You should never need to call unreference() yourself. If this fixes the
> > memory leak problem, 
> >   
> Yes, it solve my problem.
> Now the memory usage is stable and < 700Kb.
> Without this unref the memory usage is growing up (very quickly, for 
> example, I need about 50 Mb to scan 3000 files).
> > then the problem is that
> > FileEnumerator::next_file() method does add an additional reference to
> > the return value, although it shouldn't.
> the underline C g_file_enumerator_next_file() function return a pointer 
> to a new created GObject (we need to call g_object_unref() to free this 
> object).
> Do you think that, there is a bug in the C++ binding?

Yes. I filed a bug about it:
http://bugzilla.gnome.org/show_bug.cgi?id=556387.

I propose not to call unreference on your own, but instead wait for a
glibmm release with the bug fixed. Or, if you really need this to work
correctly and you can't wait for a release, you could maybe do something
like:

Glib::RefPtr<Gio::FileInfo> info = enumerator->next_file();
if(G_OBJECT(info->gobj())->ref_count > 1) info->unreference();

This way, the unreference will only be called as long as the bug is not
fixed in glibmm.

> If you want to test, here is source code of programs :
> 
> http://yojik.shtooka.net/gio.cc (giomm version)
> http://yojik.shtooka.net/gio.c (gio version)
> 
> Regards,
> Nicolas

Armin

> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]