[mapserver-users] memory leaks

matt matt at aruke.com
Thu May 10 02:50:27 EDT 2001


hi,

i'm using mapserver 3.3.011 on redhat 6.2.  i'm generating my map image
using mapscript perl module on mod_perl 1.25 on apache 1.3.9.

i'm not doing anything complicated, just grabbing a map file and generating
the image, my problem is that when i'm monitoring my memory usage increases
pretty darn fast when printing heavy maps.

i've included code that i'm using at the bottom, if anyone sees anything
obviously stupid i'd be happy to hear what it is.  i'm a cold fusion
programmer a little new to mod perl.

my goal right now is to share as much memory as possible, i've already done
a perlrequire to a script that loads mapscript and all my other modules into
the parent process,

i'm guessing my $map and $img vars are my biggest concern, is there anyway
that i can code this so that i am sharing these variables across all httpd
processes(assuming i'm not already) like my modules?

also rather than create new map objects on each request i tried

    if (!defined $map) {$map = new mapObj(file);}

but when i printed the map it had garbled data from the prviously drawn map,
is there a way to flush/clean out the image so this works?


any help would be greatly appreciated,

matt

------ here's a stripped version of my code, i call it from within an html
img tag. --------------
#!/usr/bin/perl
use mapscript;
use XBase;
require "glbLib/parse_form.pl";
require "glbLib/util.pl";

my %formdata;
%formdata = parse_form();
my @ti = localtime(time);
###### parse query string for vars ##########
my $key;
my ($lat,$lon,$zoom);
my $zm;
my $filename;
my $flvar = do_count("./","mapctr",1000);
my $mapfile;
my $numpoints = 0;
##### create a filename using time and file numbers ####

$filename =
"MS_". at ti[5]."-". at ti[4]."-". at ti[3]."--". at ti[2]."-". at ti[1]."-". at ti[0]."*".$fl
var;
$mapfile = "/usr/local/apache/htdocs/tmp/".$filename;
  foreach $key (sort keys(%formdata)){
    if ($key =~m/mlat/){
      $lat = $formdata{$key};
    }
    elsif ($key =~m/mlon/){
      $lon = $formdata{$key};
    }
    elsif ($key =~m/zoom/){
      $zoom = $formdata{$key};
    }
 }

$map = new mapObj('/usr/local/apache/perl/demo.map');

my ($CVlat,$CVlon) = latToMeter($lat);
my $latdf = $zoom * 500 * $CVlat;
my $londf = $zoom * 500 * $CVlon;
$map->{extent}->{maxx} = $lon + $londf;
$map->{extent}->{minx} = $lon - $londf;
$map->{extent}->{maxy} = $lat + $latdf;
$map->{extent}->{miny} = $lat - $latdf;
$img = $map->draw() or die('unable to draw map');

####################### draw map and save #################

$map->drawLabelCache($img);
mapscript::msSaveImage($img,$mapfile,0,0);
mapscript::msFreeImage($img);

##### read in file and stream it into page, set content type. ####

print "Content-type: image/gif\r\n\r\n";
open(FILE,$mapfile);
binmode(FILE);
@buffer = <FILE>;
foreach (@buffer){
  print $_;
}
close(FILE);
system("rm -f $mapfile");
undef $map;
############################ end ############################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20010510/bb15389e/attachment.html


More information about the mapserver-users mailing list