RE: Memory management with GdkPixbuf
- From: martyn 2 russell bt com
- To: gtk-app-devel-list gnome org
- Subject: RE: Memory management with GdkPixbuf
- Date: Tue, 30 Sep 2003 12:30:02 +0100
I am using the GdkPixbuf function
wPixbuf = gdk_pixbuf_new_from_file ( path , NULL ) ;
to read jpeg files as follows. After copying the image bytes,
I try to
liberate the memory with
g_object_unref (wPixbuf);
but checking the system memory it's clear that the program is
not freeing the
allocated memory and because I work with video sequences, it
ens up running
out of memory. Could anyone possibly tell me what I'm doing
wrong?
The way you are unreferencing the memory is perfectly normal. That is
exactly how you are supposed to use it. This basically means you are
finished with your reference to the object. If GTK still owns a reference
to it, then the memory will not be free'd until GTK has finished with it and
the reference count drops to 0.
bool Image::loadImage ( const char *path )
{
gint nrws , nysz ;
if ( g_file_test (path, G_FILE_TEST_EXISTS) != TRUE )
return false ;
GdkPixbuf *wPixbuf = gdk_pixbuf_new_from_file ( path
, NULL ) ;
if ( wPixbuf == NULL ) return false ;
nrws = gdk_pixbuf_get_rowstride (wPixbuf) ;
nysz = gdk_pixbuf_get_height (wPixbuf) ;
if ( nrws != rws || nysz != ysz )
{
xsz = gdk_pixbuf_get_width (wPixbuf) ;
ysz = nysz ; rws = nrws ;
nch = gdk_pixbuf_get_n_channels (wPixbuf) ;
bps = gdk_pixbuf_get_bits_per_sample (wPixbuf) ;
imgbsz = (glong)(rws) * ysz ;
if ( pixBuf != NULL ) g_free((gpointer)(pixBuf)) ;
}
pixBuf = (guchar*) g_memdup (
(gconstpointer)gdk_pixbuf_get_pixels(wPixbuf),imgbsz) ;
g_string_assign (fileN,path);
g_object_unref (wPixbuf);
if ( pixBuf == NULL ) return bready=false ;
return bready=true ;
}
I notice you are using g_memdup(). What is the purpose of pixBuf variable?
Are you using it to set an image?
Regards,
Martyn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]