problem with tk or tk:jpeg memory usage 
Author Message
 problem with tk or tk:jpeg memory usage

This script when run shows how to replay the memory usage problems
i've been having with Tk; Tk:JPEG;

If anyone knows of a solution or even a idea to get around it, please
let me know.

Thanx
StevoIE

-------------------------------------------

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{


$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);

Quote:
}
}



Fri, 04 Feb 2005 17:12:02 GMT  
 problem with tk or tk:jpeg memory usage


Quote:
> This script when run shows how to replay the memory usage problems
> i've been having with Tk; Tk:JPEG;

> If anyone knows of a solution or even a idea to get around it, please
> let me know.

> Thanx
> StevoIE

> -------------------------------------------

> 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=>\&browseIm
ages)

Quote:
> ->place(-x=>30,-y=>80);

> MainLoop;

> sub browseImages{


> $imageCounter=1;
> undef($imageHandler);

> #Create the browse Window
> $bw = MainWindow->new;

I strongly suggest a Toplevel here instead?!
$bw = $mw->Toplevel;

- Show quoted text -

Quote:
> $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");

#You must make sure you delete your images upon closing the toplevel
#To all -  Why is the 'delete' method of Tk::Photo undocumented?

$top->protocol('WM_DELETE_WINDOW',sub{

    });

Quote:
> #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=>\&nextimag
e)

Quote:
> ->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);
> }

Another suggestion: Why destroy the Label and re-create? Do a configure on it
instead.
$imageHandler->configure(-image=>$imageArray[$imageCounter]);

Quote:

> }

Jack


Sat, 05 Feb 2005 01:38:45 GMT  
 problem with tk or tk:jpeg memory usage

Quote:

> This script when run shows how to replay the memory usage problems
> i've been having with Tk; Tk:JPEG;

> If anyone knows of a solution or even a idea to get around it, please
> let me know.

I did not read the complete source, but a grep for "->delete" found
nothing :-) My advice: look at the Tk::Photo or Tk::Image
documentation for the delete() method.

Regards,
        Slaven

--

Tk-AppMaster: a perl/Tk module launcher designed for handhelds
        http://tk-appmaster.sf.net



Sat, 05 Feb 2005 01:30:15 GMT  
 problem with tk or tk:jpeg memory usage

Quote:



> > This script when run shows how to replay the memory usage problems
> > i've been having with Tk; Tk:JPEG;

> > If anyone knows of a solution or even a idea to get around it, please
> > let me know.

> > Thanx
> > StevoIE

> > -------------------------------------------

> > 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=>\&browseIm
> ages)
> > ->place(-x=>30,-y=>80);

> > MainLoop;

> > sub browseImages{


> > $imageCounter=1;
> > undef($imageHandler);

> > #Create the browse Window
> > $bw = MainWindow->new;

> I strongly suggest a Toplevel here instead?!
> $bw = $mw->Toplevel;

> > $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");

> #You must make sure you delete your images upon closing the toplevel
> #To all -  Why is the 'delete' method of Tk::Photo undocumented?

It's not undocumented --- it's in Tk::Image. But it's undocumented
that Tk::Photo is a subclass of Tk::Image (well, the first line in the
pod description says "A photo is an image...", but this is not very
clear).

Regards,
        Slaven

--

need xpm or ppm output from GD?
        http://search.cpan.org/search?mode=module&query=GD::Convert



Sat, 05 Feb 2005 01:56:14 GMT  
 problem with tk or tk:jpeg memory usage

Quote:

> > #To all -  Why is the 'delete' method of Tk::Photo undocumented?

> It's not undocumented --- it's in Tk::Image. But it's undocumented
> that Tk::Photo is a subclass of Tk::Image (well, the first line in the
> pod description says "A photo is an image...", but this is not very
> clear).

Well - one would certainly not want to duplicate the documentation. In the
'IMAGE METHOD' section of the pod's for Bitmap, Pixmap and Photo all it says is:

"When a [pixmap/bitmap/photo] image is created, Tk also creates a new object.
This object supports the configure and cget methods described in the Tk::options
manpage which can be used to enquire and modify the options described above."

You are right Slaven, it certainly is not explicit that I can use the Tk::Image
methods here?

I suggest wording like this:

IMAGE METHODS
"When a [pixmap/bitmap/photo] image is created, Tk also creates a new object.
This object is a sub-class of a Tk::Image, and therefore supports all methods
described in the Tk::Image manpage. This object also supports the configure and
cget methods described in the Tk::options manpage which can be used to enquire
and modify the options described above."

Since this is a FAQ - I thought that adding another section to the
bitmap/photo/pixmap pods would be in order.

NOTES
"Images can use up a large amount of memory. Remember to use the ->delete method
(as described in Tk::Image) when you are finished with the object and it is no
longer needed"

It would be nice for this (or something) similar made it into 800.025 or
804.xxx. Who takes care of the pods?

Jack



Sat, 05 Feb 2005 02:19:59 GMT  
 problem with tk or tk:jpeg memory usage

Quote:




> > > #To all -  Why is the 'delete' method of Tk::Photo undocumented?

> > It's not undocumented --- it's in Tk::Image. But it's undocumented
> > that Tk::Photo is a subclass of Tk::Image (well, the first line in the
> > pod description says "A photo is an image...", but this is not very
> > clear).

> Well - one would certainly not want to duplicate the documentation. In the
> 'IMAGE METHOD' section of the pod's for Bitmap, Pixmap and Photo all it says is:

> "When a [pixmap/bitmap/photo] image is created, Tk also creates a new object.
> This object supports the configure and cget methods described in the Tk::options
> manpage which can be used to enquire and modify the options described above."

> You are right Slaven, it certainly is not explicit that I can use the Tk::Image
> methods here?

> I suggest wording like this:

> IMAGE METHODS
> "When a [pixmap/bitmap/photo] image is created, Tk also creates a new object.
> This object is a sub-class of a Tk::Image, and therefore supports all methods
> described in the Tk::Image manpage. This object also supports the configure and
> cget methods described in the Tk::options manpage which can be used to enquire
> and modify the options described above."

I think this is too verbose --- a class hierarchy section like in the
Mail::Box modules should be sufficient:

CLASS HIERARCHY
        Tk::Photo
        is a Tk::Image

This class hierarchy section could be used throughout the whole
Perl/Tk documentation.

Or, alternatively, the wording like in the Tk::Tree manpage:

SUPER-CLASS
       The Tk::Photo class is derived from the Tk::Image class and
       inherits all the methods and options of its
       super-class.

Quote:

> Since this is a FAQ - I thought that adding another section to the
> bitmap/photo/pixmap pods would be in order.

> NOTES
> "Images can use up a large amount of memory. Remember to use the ->delete method
> (as described in Tk::Image) when you are finished with the object and it is no
> longer needed"

> It would be nice for this (or something) similar made it into 800.025 or
> 804.xxx. Who takes care of the pods?

Well, Nick is the maintainer of Perl/Tk.

Regards,
        Slaven

--

Start a WWW browser - OS independent:
        http://user.cs.tu-berlin.de/~eserte/src/perl/WWWBrowser/



Sat, 05 Feb 2005 05:16:01 GMT  
 problem with tk or tk:jpeg memory usage
Thanx for all the suggestions.
tried the ->delete on the images but it didn't work, the memory was
still been used after the delete calls.  The only way i can free up
the memory is if i shut down the program!! unacceptable.
I used $imageHandler->imageNames of Tk::Image which prints out all the
images associated with the mainWindow, tried this before and after the
->delete on all the images, the list of image names was the same,
indicating that it wasn't removing the images from program.

Any other ideas?
Thanx
StevoIE



Sat, 05 Feb 2005 17:20:50 GMT  
 problem with tk or tk:jpeg memory usage

Quote:
> Thanx for all the suggestions.
> tried the ->delete on the images but it didn't work, the memory was
> still been used after the delete calls.  The only way i can free up
> the memory is if i shut down the program!! unacceptable.

Are you sure? Remember, that you are not looking for the memory to 'decrease',
only for it NOT to increase. Once perl has grabbed some memory it is unlikely to
release it back to the system.

Quote:
> I used $imageHandler->imageNames of Tk::Image which prints out all the
> images associated with the mainWindow, tried this before and after the
> ->delete on all the images, the list of image names was the same,
> indicating that it wasn't removing the images from program.

> Any other ideas?

Did you make the change to a toplevel?

Run 'top'.

Then try creating your 'Toplevel' - browse a few pictures.
Close the toplevel.
Note the current memory.
Repeat process by pressing your browswimage button again.

Did the memory increase?

Jack



Sun, 06 Feb 2005 01:19:45 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. problem with tk or tk:jpeg memory usage

2. Tk::PNG and Tk::JPeg module Problem

3. Out of memory problem in Tk/MkMainWindow.pm (Perl/Tk) on HP-UX 11

4. Out of memory problem in Tk/MkMainWindow.pm (Perl/Tk) on HP-UX 11

5. Solution found - Perl Module Tk::JPEG is not compatible with Tk

6. Help Tk::Jpeg and Tk 800.023

7. excessive memory usage in Tk script

8. Memory usage in Tk

9. Problems compiling Tk::JPEG

10. Problems compiling Tk::JPEG

11. Tk::JPEG install problem

 

 
Powered by phpBB® Forum Software