# Simple image viewer questions

**URL:** <https://www.ruby-forum.com/t/simple-image-viewer-questions/118487>\
**Category:** Ruby-Gnome 2\
**Created:** [October 27, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/simple-image-viewer-questions/118487 "2007-10-27T18:43:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 27, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/simple-image-viewer-questions/118487/1 "2007-10-27T18:43:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 27, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/simple-image-viewer-questions/118487/2 "2007-10-27T19:09:28Z")

</div>

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 removed\_email\_address@domain.invalid:
