Re: [Gimp-developer] Image reference count problem in plugin

Top Page

Reply to this message
Author: Sven Neumann
Date:  
To: David Hodson
CC: gimp-developer
Subject: Re: [Gimp-developer] Image reference count problem in plugin
Hi,

I've just tried this with GIMP 2.2-pre2 from the Script-Fu console and
you are right that the reference handling is somewhat confusing.
Perhaps gimp_displays_reconnect() should hand the reference over to
the display just as gimp_display_new() does. That would however mean
that if you reconnected the display again your image would be gone
since the last reference on it just got dropped.

So I think the current behaviour is coorect but should perhaps be
documented better. Your plug-in will have to call gimp_image_delete()
on the new image in order to drop the reference it holds on it.
Here's the example you gave:

gint newImage = gimp_file_load (...);
gimp_displays_reconnect (oldImage, newImage);
gimp_image_delete (oldImage);

That last line is wrong since you never owned a reference on that
image and it is already gone at that point. It should read instead:

gint newImage = gimp_file_load (...);
gimp_displays_reconnect (oldImage, newImage);
gimp_image_delete (newImage);


Sven