Simple image viewer questions

Hi.

I’d like to create a simple image viewer.
At the moment it is enough to have one button
and a widget that displays predefined images.
I used glade-3 to create a skeleton.

It works but when watching the memory consumption using ‘top’,
I noticed that the script allocates about 20MB more memory
each time I click the button and the next image is loaded.
Do you have an idea how this can be avoided?

I chose Gdk::Pixbuf because I think it’s the only way to
change the resolution of the image loaded.

Here’s a code snippet of what I tried:

class ImgselectorGlade
include GetText

def initialize(path_or_data, root = nil, domain = nil, localedir =
nil, flag = GladeXML::FILE)
GetText.bindtextdomain(domain, localedir, nil, “UTF-8”)
@glade = GladeXML.new(path_or_data, root, domain, localedir, flag)
{|handler| method(handler)}

# Images to display
@images = "test.jpg", "test2.jpg"

# Count of images
@count = @images.length
@counter = 0

# Get the main window and show it
@window = @glade.get_widget("mainWindow")
@window.show

# Get the image widget
@image_widget = @glade.get_widget("imageWindow")

on_buttonNext_clicked

end

def on_buttonNext_clicked
if (@counter += 1) >= @count
@counter = 0
end

image = Gdk::Pixbuf.new(@images[@counter], 1024, 768)
@image_widget.set(image)

end

def on_quit
Gtk.main_quit
end

end


Flo

Hi,

the garbage collector doesn’t work that good for things like big data
chunks like images. Simply put a GC.start after displaying a new image.

Cheers
detlef

Am Samstag, den 27.10.2007, 18:43 +0200 schrieb [email protected]: