Re: memory management with glibmm & giomm
- From: Armin Burgmeier <armin arbur net>
- To: nico <nico yojik eu>
- Cc: gtkmm-list gnome org
- Subject: Re: memory management with glibmm & giomm
- Date: Tue, 14 Oct 2008 20:29:47 +0200
On Tue, 2008-10-14 at 20:04 +0200, nico wrote:
> Hello,
>
> One week ago, I sent an email about a leak of memory of a program that
> list files of a directory (using giomm).
> My program was inspired by an official sample code (that we can get
> here:
> http://svn.gnome.org/viewvc/gtkmm-documentation/trunk/examples/book/giomm/directory_list/)
>
> In fact, there is a bug in this sample program:
>
> > *Glib*::RefPtr<Gio::FileInfo> file_info = enumerator->next_file();
> > *while*(file_info)
> > {
> > *std*::cout << *"file: "* << file_info->get_name() << std::endl;
> > file_info = enumerator->next_file();
> > }
> This piece of code create FileInfo objects and never unref them.
> The right code would have beeb:
> > Glib::RefPtr<Gio::FileInfo> file_info = enumerator->next_file();
> > while(file_info)
> > {
> > std::cout << "file: " << file_info->get_name() << std::endl;
> > file_info = enumerator->next_file();
> > file_info->unreference();
> > }
> Or, an other variant :
> > while(Glib::RefPtr<Gio::FileInfo> file_info = enumerator->next_file()) {
> > std::cout << "file: " << file_info->get_name() << std::endl;
> > file_info->unreference();
> > }
You should never need to call unreference() yourself. If this fixes the
memory leak problem, then the problem is that
FileEnumerator::next_file() method does add an additional reference to
the return value, although it shouldn't.
> I'll try to report the bug,
Thanks.
> Regards,
> Nicolas
Armin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]