Re: memory management with glibmm & giomm
- From: nico <nico yojik eu>
- To: gtkmm-list gnome org
- Subject: Re: memory management with glibmm & giomm
- Date: Tue, 14 Oct 2008 20:04:22 +0200
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();
}
I'll try to report the bug,
Regards,
Nicolas
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]