GdkPixbuf 的申请与释放

最近,在用GTK在线程中显示图片,当

         GdkPixbuf *pixbuf;
          pixbuf=gdk_pixbuf_new_from_file("X.jpg",NULL);

          delete pixbuf;//释放不掉。之后内存占用渐渐增至100%。崩溃,死机。

经过调查原因是

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.

 

refrence from:http://www.linuxfans.org/bbs/thread-62574-1-1.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jiang_dlut

你的鼓将是我创作的最大动力。。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值