Memory Leak on modify_bg



Greetings All, 

  I am working on a rather large Perl program that monitors data from an RS232 port, and allows for sending 
data as well. I have built a GUI using 
the GTK2 interface and the various calls. It has been working well up until a couple of weeks ago when I 
decided to add some color to a few of the controls. 

  The program sets a timer that pops every 40ms. The routine that executes
on this pop checks some status, and updates the display based on that status. 
When I added color to the display, the program would terminate after about
15 minutes with a OUT OF MEMORY error. I have narrowed the culprit to a usage of modify_bg. If I comment out 
this reference, the program will run forever, and memory usage is fairly constant (as seen with a memory 
monitor program). If I include the line of code, the memory usage keeps increasing until all available is 
used. 


I have narrowed the offending code to a small subset and am including it here. When run, this snippet 
exhibits the same behavior. 
 
Can some kind soul tell me what I am doing wrong? It would be nice 
(although not essential) to have some status color on my controls. 



  Thanx in advance.

  Rich 

##########################################
#   Memory usage problem 
##########################################

use strict;
use Gtk2 '-init';
use constant TRUE  => 1;
use constant FALSE => 0;

my $green    = Gtk2::Gdk::Color->new (0x0000,0xffff,0x0000);
my $red      = Gtk2::Gdk::Color->new (0xffff,0x0000,0x0000);
my $connected = FALSE;
my $connect_status = Gtk2::Button->new_with_label("");
my $window = Gtk2::Window->new;
$window ->set_title("testing...");
$window ->add($connect_status);  
$window -> show_all;
my $counter = 0;
my $timer = Glib::Timeout->add(40,\&update_display, undef, 10);
Gtk2->main;   
  
sub update_display {
   my $hz;
   my $color;
   if ($connected) {
      $hz = "connected   ";
      $color = $green;
   }
   else {
      $hz = "disconnected";
      $color = $red;
   }
   $connect_status->set_label($hz);
  
   #### If this statement is commented, no memory increase is seen
   $connect_status->modify_bg('normal',$color);
  
  
   ### change the status after 10 passes
   if (++$counter> 10) {
      $connected = !$connected;
      $counter = 0;
   }
   return TRUE; 
}

 



      



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]