Vala 中的 Gdk.Pixbuf 内存泄漏,还是其他什么?
这是一个简单的问题。你能帮我找到这段 Vala 代码中的内存泄漏吗? 如果有帮助的话我也可以发布生成的c代码^^
using GLib;
using Gtk;
using Gee;
void test1 ()
{
Gee.ArrayList<Gdk.Pixbuf> list = new Gee.ArrayList<Gdk.Pixbuf>();
for( int a = 0; a < 10000; a++)
{
string path = "/usr/share/icons/gnome/48x48/stock/data/stock_lock.png";
list.add( new Gdk.Pixbuf.from_file( path ) );
}
list.clear();
// when the function returns it *should* free all alocated memory, or am I missing something?
}
int main (string[] args)
{
Gtk.init( ref args);
// the memory usage here is ~3mb
test1();
// here it is ~94mb
Gtk.main();
return 0;
}
here is a simple question. Can you help me find the memory leak in this Vala code ?
If it helps I can post the generated c code too ^^
using GLib;
using Gtk;
using Gee;
void test1 ()
{
Gee.ArrayList<Gdk.Pixbuf> list = new Gee.ArrayList<Gdk.Pixbuf>();
for( int a = 0; a < 10000; a++)
{
string path = "/usr/share/icons/gnome/48x48/stock/data/stock_lock.png";
list.add( new Gdk.Pixbuf.from_file( path ) );
}
list.clear();
// when the function returns it *should* free all alocated memory, or am I missing something?
}
int main (string[] args)
{
Gtk.init( ref args);
// the memory usage here is ~3mb
test1();
// here it is ~94mb
Gtk.main();
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在最新版本的 Vala(0.10.1 和 0.11.1)上复制了这个。我查看了 valac 生成的 .c 代码,没有发现明显的问题,尽管很明显 pixbuf 正在泄漏(valgrind 证实了这一点)。我在这里将其报告为错误:
https://bugzilla.gnome.org/show_bug.cgi ?id=633869
更新:该错误已修复。调查显示本身没有内存泄漏,但(最有可能)内存在被子分配器或类似的东西释放时正在被分配和保留。正如 Evan 指出的,如果您在循环中调用测试函数,总内存大小永远不会超过 90MB,这表明它不是内存泄漏。
I've reproduced this on the latest versions of Vala (0.10.1 and 0.11.1). I've looked over the .c code valac generates and don't see an obvious problem there, although it's obvious the pixbufs are leaking (valgrind confirms this). I reported it as a bug here:
https://bugzilla.gnome.org/show_bug.cgi?id=633869
Update: The bug is closed. Investigation shows there is no memory leak per se, but (most likely) that the memory is being allocated and held when it's freed by a suballocator or some-such. As Evan pointed out, if you call the test function in a loop, the total memory size never exceeds 90MB, indicating it's not a memory leak.