QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1249|回复: 4

???????如何释放GdkPixbuf空间??????

[复制链接]
发表于 2004-4-11 14:55:04 | 显示全部楼层 |阅读模式
从文件中读入图像数据到GdkPixbuf, GDK会自己给它分配一块空间,并且返回该地址,现在的问题是如何释放这块空间,或者有没有其他办法进行连续读入图像,因为不进行释放,连续进的图片够多时,mem和swap空间就耗完了,程序也就terminated!



谢了!
发表于 2004-4-11 15:14:10 | 显示全部楼层
free或者g_free试试
回复

使用道具 举报

 楼主| 发表于 2004-4-11 23:11:10 | 显示全部楼层
[quote:5dd410e327="mozilla"]free或者g_free试试[/quote]

不行!

比如说:
处理目录dir下的所有图像文件(以下API只是为了说明问题,并不存在)
GdkPixbuf *mybuf ;
char  *filename = get_next_file_name(dir);
while(filename没有被处理)
{
    mybuf = gdk_pixbuf_new_from_file(filename, error);

    // Handle mybuf here........

    //接下来需要释放mybuf得到的空间!!!! <==
    // 如果这里不释放空间,随着gdk_pixbuf_new_from_file不断的度入图像数据,没有释放的内存越占越大,直至耗尽。

    // 但这里直接用free, g_free, 不行的!!

    filename = get_next_file_name(dir);
}

gdk_pixbuf_new_from_file的原码需要看一下,是什么机制来申请空间的。

知道后,马上贴出;如果谁已经知道,请告知,共同探讨!

谢!
回复

使用道具 举报

发表于 2004-4-12 09:44:33 | 显示全部楼层
GdkPixbuf structures are reference counted. This means that an application can share a single pixbuf among many parts of the code. When a piece of the program needs to keep a pointer to a pixbuf, it should add a reference to it by calling g_object_ref(). When it no longer needs the pixbuf, it should subtract a reference by calling g_object_unref(). The pixbuf will be destroyed when its reference count drops to zero. Newly-created GdkPixbuf structures start with a reference count of one.

Note
As GdkPixbuf is derived from GObject now, gdk_pixbuf_ref() and gdk_pixbuf_unref() are deprecated in favour of g_object_ref() and g_object_unref() resp.

Finalizing a pixbuf means to free its pixel data and to free the GdkPixbuf structure itself. Most of the library functions that create GdkPixbuf structures create the pixel data by themselves and define the way it should be freed; you do not need to worry about those. The only function that lets you specify how to free the pixel data is gdk_pixbuf_new_from_data(). Since you pass it a pre-allocated pixel buffer, you must also specify a way to free that data. This is done with a function of type GdkPixbufDestroyNotify. When a pixbuf created with gdk_pixbuf_new_from_data() is finalized, your destroy notification function will be called, and it is its responsibility to free the pixel array.
回复

使用道具 举报

 楼主| 发表于 2004-4-12 22:17:11 | 显示全部楼层
xiaowu_l, 以后有问题向你请教,可不可以留个联系方式(msn),我的是xiaosoft(at)hotmail.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-8 14:01 , Processed in 0.059559 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表