-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David Nečas (Yeti) wrote:
> On Fri, Aug 31, 2007 at 02:11:15PM -0700, Mike Melanson wrote:
>>> I have an application, that amoung other things, is receiving a jpg file
>>> from a network connection. Once that file is in memory (it's relatively
>>> small), I wish to load it into a GtkImage (so that I can display it,
>>> e.g. by adding the GtkImage to a vbox, or something like that).
>>>
>>> ...
>> My first impulse is that you will need to drag libjpeg into this (pretty
>> standard everywhere) and delegate image decoding over to that module.
>> Then create a new image in memory with gdk_image_new() and copy the
>> decoded RGB data over.
> 
> No, explicit use of libjpeg is not necessary.  Create a
> GdkPixbufLoader, feed the in-memory image date to it with
> gdk_pixbuf_loader_write() and if everything is all right
> fetch the GdkPixbuf from it.  Then construct the GtkImage
> with gtk_image_new_from_pixbuf().

This works fine, but now I have a concern as regards to memory leak.

Here is the scenerio I have.

I have a gtk application that, amoung other things is receiving packets from a
server. Sometimes those packets will contain a url to a jpg, which I them fetch,
and then need to display.

Essentially, once the jpg image is fetched, I do:

        
        my_loader = gdk_pixbuf_loader_new();
        rv = gdk_pixbuf_loader_write(my_loader, jpg_image, jpg_image_size, 0);
        if (!rv) {
                /* loading jpg image failed */
                return NULL;
        }
        rv = gdk_pixbuf_loader_close(my_loader, 0);
        if (!rv) {
                /* closing jpg image loader failed */
                return NULL;
        }
        jpg_pixbuf = gdk_pixbuf_loader_get_pixbuf(my_loader);
        image  = gtk_image_new_from_pixbuf(jpg_pixbuf);

And then I add the image to a display widget via:

        gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, TRUE, 4);

I have run the application under valgrind, and valgrind is detecting a number of
leaks relating specifically to the gdk_pixbuf_loader_write's allocation of
various memory structures.

I should hasten to add that when I run valgrind, I pass the flags:

        G_DEBUG=gc-friendly G_SLICE=always-malloc

to lessen false positives.

The reason for new'ing a new loader each time is that, from the documentation,
it appears that once I "loader_close()", I can no longer write to the loader,
and it is not clear that I can do sequential loader writes's followed by
loader_get_pixbuf's, thereby reusing the same (original) loader.

I also am not seeing a convenient way to destroy the loader. (it does happen to
have a finalize routine, but I'm not sure how to invoke it :)

I'm looking for thoughts as to:

        destroying the loader, so that it will free up all of it's internal
        memory (the close doesn't free up all of the interally allocated
        memory!)

  or
        reusing the loader (if possible).


many thanks in advance,

- -Greg Hosler

> Yeti
> 
> --
> http://gwyddion.net/
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


- --
+---------------------------------------------------------------------+

Please also check the log file at "/dev/null" for additional information.
                (from /var/log/Xorg.setup.log)

| Greg Hosler                                   [EMAIL PROTECTED]    |
+---------------------------------------------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFG48so404fl/0CV/QRAkwuAJ47exv2lic1LHSWi85jxXOxU+ycJACglTxm
2elUbrCyGumYFV55QKPw8Jc=
=MgFV
-----END PGP SIGNATURE-----
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to