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