[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] WaitNextEvent Memory Leak?



Greetings,

I am trying to put a GUI on some perl scripts that I have
built... 

My first attempt is to simply ask for an input file name and
and output file name, then generate the output file from the
input file data.

The following code will set me up, but only if I don't dawdle...

If I open the "About this Mac" display to watch memory usage
and start the program, pick a couple of files and then just
sit there and do nothing I can watch the size bar for MacPerl
slowing creep up to the end of it's allocation and shortly
thereafter drop into MacsBug ;(

The problem gotta be in waitnextevent cuz that is where it's
sitting... This evil behavior occurs in 5.2.1a1 and 5.2.0r4

Any suggestions? Here is the code...
  Jerry
  levan@eagle.eku.edu

#!perl -w
use strict;
use Mac::Dialogs;
use Mac::Events;
use Mac::Windows;
use Mac::StandardFile;
my($dlg);

$dlg = MacDialog->new(
   Rect->new(423,280,852,486), # Dialog  rectangle
   'PDB->Info',                # Dialog title
   1,                          # Is Visible?
   movableDBoxProc(),          # window style
   0,                          # no goaway box
   [kButtonDialogItem(),
       Rect->new(31,167,89,187),'Execute'], # item 1
   [kButtonDialogItem(),
       Rect->new(189,167,247,187),'Cancel'], # item 2
   [kButtonDialogItem(),
       Rect->new(342,52,400,70),'Browse'],   # item 3
   [kButtonDialogItem(),
       Rect->new(342,122,400,140),'Browse'], # item 4
   [ kStaticTextDialogItem(),
      Rect->new(22,15,155,35),
      'Select Input File'],                   # item 5
   [ kStaticTextDialogItem(),
      Rect->new(23,95,163,114),
      'Select Output File'],                  # item 6
   [ kEditTextDialogItem(),
      Rect->new(30,50,320,70), ''],           # item 7 (input file)
   [ kEditTextDialogItem(),
      Rect->new(30,120,320,140), '']          # item 8  (output file)
);

SetDialogCancelItem ($dlg->window(), 2);
SetDialogDefaultItem($dlg->window(), 1);
SelectDialogItemText($dlg->window(), 7);

$dlg->item_hit(1 => \&d1);      # execute the conversion 
$dlg->item_hit(2 => \&d2);      # Cancel the conversion and quit
$dlg->item_hit(3 => \&d3);      # Call up the input file browser
$dlg->item_hit(4 => \&d4);      # Call up the output file browser


while ($dlg->window()) {
 WaitNextEvent();
}

sub d1 {
  my($dlg) = @_;
  print "You Clicked Execute. \n" ;
  $dlg->dispose();
  exit 1;
}

sub d2 {
  my ($dlg) = @_;
  print "You clicked Cancel.\n";
  $dlg->dispose();
  exit 1;
}

 sub d3 {
   my($dlg) = @_;
   my $file ;

   print "You Clicked on the Input file button.\n";
   $file = StandardGetFile(0,'TEXT');
   if($file->sfGood()) {
     print "You chose: ",$file->sfFile(),"\n";
    $dlg->item_text(7,$file->sfFile());
    }
    else {
      print "You Cancelled the dialog\n";
    }
   return 1;
 }

 sub d4 {
   my($dlg) = @_;
   my($answer,$file);

   print "You clicked on the Output file selector button.\n";
   $file = StandardPutFile('Filename: ' ,"");
   if($file->sfGood()) {  # From MacPerl Book...
       $dlg->item_text(8,$file->sfFile());
     }
 
    return 1;
}
       

END {
       $dlg->dispose() if ( defined($dlg));
    }

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org