Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

next problem - Tk::JPEG memory usage

Status
Not open for further replies.

Stevoie

Programmer
Jun 7, 2001
68
IE
I've posted this problem before but I didn't get much back so I'll try again.

Heres the code:

#Create the Main Window
$mw = MainWindow->new;

#Create the frame to display the images
$frame2 = $mw->Frame(-background=>'black',-width=>712,-height=>568)->pack(-anchor=>'ne');

#Load the images
$wittitle = $mw->Photo('23',-file => "images/subtitle.jpg");
$mainimage = $mw->Photo('22',-file => "images/viv5.jpg");

$games = $mw->Photo('44',-file => "images/games.jpg");
$apps = $mw->Photo('45',-file => "images/apps.jpg");


#The above image handles are put in a array. Each time a button is pressed, it cycles through this array, setting the $image below to a image handle in the array


$program_image = $frame2->Label('-image'=>$image, -borderwidth=>0)->place(-x=>0,-y=>0);


The way the program works:
program calls a function
function creates a new mainwindow
loads all the images
setups a button to cycle through them
user hits a exit button
destroys the mainwindow
exits function
returns to main screen

user can call the function again - if they do, this is where the memory usage grows as the user exits and enters the function repeatedly(have to allow this).

Problem: when it exits the function, it doesn't free up the memory used by the images.
Solution:?? This is only a problem since the latest version of either Tk or TK::JPEG - don't know which and I can't find the older versions of them, to test them.

If you need more info let me know

Thanx
StevoIE
 
Steve,

Can you recreate the memory leak with a small test script?

The authors of TK and TK::JPEG would probably be interested if you can. Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
ok here it is:

use Tk;
use Tk::JPEG;


#Create the Main Window which has a single button to start the browse window
my $mw = MainWindow->new;
$mw->configure(-background=>'black');
$mw->geometry("100x200+20+20");

my $image = $mw->Photo('1',-file => "images/button1.gif");

$mw->Button(-image=>$image ,-foreground=>'white',-background=>'black',-cursor=>'hand2',-command=>\&browseImages)
->place(-x=>30,-y=>80);


MainLoop;


sub browseImages{

undef(@imageArray);
$imageCounter=1;
undef($imageHandler);

#Create the browse Window
$bw = MainWindow->new;
$bw->configure(-background=>'black');
$bw->geometry("800x600+20+20");


#load images - usually i would use some function that would get all the images in a specified dir and then load them in the array. i load them all at the beginning to speed up the browsing of the images
#this allows for fast browsing through the images
#but it does use up a lot of memory but i'm willing to allow a certain amount to be taken eq 20MB
#but when this window closes it doesn't free up the loaded images, it just gets bigger every time the browse window opens, you should really try with 20-30 pics to really see the memory usage

$imageArray[0] = $bw->Photo('3',-file => "images/button2.gif");
$imageArray[1] = $bw->Photo('4',-file => "images/image1.jpg");

$imageArray[2] = $bw->Photo('5',-file => "images/image2.jpg");
$imageArray[3] = $bw->Photo('6',-file => "images/image3.jpg");

$imageArray[4] = $bw->Photo('7',-file => "images/image4.jpg");
$imageArray[5] = $bw->Photo('8',-file => "images/image5.gif");

#Load the default image
$imageHandler = $bw->Label('-image' => $imageArray[1],-borderwidth=>0 )->place(-x=>0,-y=>0);

$bw->Button(-image=>$imageArray[0] ,-foreground=>'white',-background=>'black',-cursor=>'hand2',-command=>\&nextimage)
->place(-x=>760,-y=>560);


sub nextimage
{
$imageCounter = ($imageCounter % 5) + 1;
$imageHandler->destroy();
$imageHandler = $bw->Label('-image'=>$imageArray[$imageCounter], -borderwidth=>0)->place(-x=>0,-y=>0);
}

}


If I'm doing something obviously wrong please tell me, and if you have any more questions, let me know
thanx
StevoIE
 
Steve,

Your code looks fine to me, you're actually undef()ing the array that holds the images.

I would pass this straight onto the Tk authors, nice small script, they shouldn't have any problem recreating the error condition. Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top