Thanks for your help. This is how i solved the problem:
#!/usr/bin/perl -w use strict; use constant WIDTH => 1000; use constant HEIGHT => 100; use constant SPEED => 1; use Cairo; use Glib qw(TRUE FALSE); use Gtk2 -init; use Gtk2::Pango; my ($text,$ticks, $cr, $layout, $desc, $area); sub initialize { $cr = Gtk2::Gdk::Cairo::Context -> create($area->window()); $layout = Gtk2::Pango::Cairo::create_layout($cr); $desc = Gtk2::Pango::FontDescription -> from_string("Sans Bold 57" +); $layout -> set_font_description($desc); $layout->set_alignment("PANGO_ALIGN_LEFT"); } sub draw_text { $cr->push_group; $layout->set_text($text); Gtk2::Pango::Cairo::update_layout($cr, $layout); my @size = $layout->get_pixel_size; $cr -> translate(-($ticks*SPEED)%$size[0],0); $cr->set_source_rgb(1.0,1.0,1.0); $cr->fill(); $cr -> set_source_rgb(0.0,0.0,0.0); my $count = int(WIDTH/$size[0]); $cr->translate(-$size[0]*2,0); for(my $i = 0; $i<=$count+1; $i++){ $cr->translate($size[0],0); Gtk2::Pango::Cairo::show_layout($cr,$layout); } $cr->pop_group_to_source; $cr->paint; } my $window = Gtk2::Window->new(); $window -> signal_connect(delete_event => sub { Gtk2 -> main_quit(); }); $area = Gtk2::DrawingArea -> new(); sub draw { $cr->rectangle(0,0,WIDTH,HEIGHT); draw_text($cr,$ticks); } sub timer { $ticks ++; draw(); return 1; } $text = 'Please specify your input file'; if($ARGV[0]){ open(INPUT_FILE, "$ARGV[0]"); $text = <INPUT_FILE>; } $ticks = 0; $window -> set_default_size(WIDTH,HEIGHT); $window -> add($area); $window->show_all(); initialize; my $timer = Glib::Timeout->add(1000/60, \&timer ,'',); Gtk2->main();
Was it Perl or GTK2 libraries bug with releasing objects after each timer callback? Should I avoid creating local (my) objects in subs?

In reply to Re: Bad, bad memory leaks in simple script by Solak
in thread Bad, bad memory leaks in simple script [solved] by Solak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.