[CF-Devel] Client memory leak

crossfire-devel-admin at archives.real-time.com crossfire-devel-admin at archives.real-time.com
Thu Jun 12 14:24:15 CDT 2003


Hi!

The GTK Unix Client 1.5.0 (and probably others) have a memory 
leak. This is how you can hopefully and simply reproduce it:

  35 key Left R drop 1 large gold nugget;invoke alchemy;get nugget
  36 key Left A drop 10 small gold;invoke alchemy;get nugget
  38 key Down A get 1 gold nugget;use_skill alchemy

Create some gold nuggets by casting alchemy to 2000 platinum 
coins. Pick them up and turn them to small nuggets by repeating 
key binding nr. 35. Put the unidentified small nuggets in a sack, 
bag, etc. With the open bag call #38 repeatedly. This takes 1 
unidentified nugget which stays apart from the identified ones 
and keep staying apart even after idendifying. The many nuggets 
in the inventory eat up memory. If you 'drop all' the single 
nuggets get merged but memory won't be freed.

For completeness ... With the bag closed #36 recycles the nuggets 
so they can be identified again in order to gain mental level.

Below is a perl script that warns you when memory gets low.

Bernhard


     
     bernhard at bb
     
     :~$ cat $(which lmwarn)
#!/usr/bin/perl -w

# This program requires the beep utility to be installed!

$hf=5000;
$lf=500;

sub commify {
	local $_  = shift;
	1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
	return $_;
}

sub freemem {
	open MEMINFO,'/proc/meminfo';
	undef $/;
	$_=<MEMINFO>;
	
	/Mem: +\d+ +\d+ +(\d+) +\d+ +(\d+) +(\d+)/;
#	my $free=$1+$2+$3;
	my $free=$1;
	/Swap: +\d+ +\d+ +(\d+)/;
	return $free+$1;
}

if (`beep -v`!~/beep/) {
	print "\almwarn requires the program beep! Please install it!\n";
	$exit=1;
}

if ($#ARGV==-1) {
	open MEMINFO,'/proc/meminfo';
	undef $/;
	$_=<MEMINFO>;
	/Mem: +(\d+)/;
	$total=$1;
	/Swap: +(\d+)/;
	$total+=$1;
	print "No limit specified. Using 1/4 total memory: "
		.int($total/1024/1024)."/4="
		.int($total/1024/1024/4)." MB.\n";
	$limit=int $total/4;
} elsif ($ARGV[0]=~/^\d+$/) {
	$limit=$ARGV[0]*1024*1024;
} else {
	print "Beeps when swap memory gets low.\n";
	print "usage: lmwarn [<limit (MB)>]\n";
	print "The frequency of the beeps relate to the amount of free 
memory:\n";
	print "$hf Hz for the warning limit.\n";
	print "$lf Hz for out of memory.\n";
	print "There will be 3 beeps:\n";
	print "The 1st indicates the amount of free memroy last time.\n";
	print "The 2nd indicates the current amount of free memory.\n";
	print "The 3rd is the out of memory frequency for reference.\n";
	print "Current free memory is ".commify(freemem())." (".
		int (freemem()/1024/1024) ." MB).\n";
	$exit=1;
}

$exit and exit;

$lastfree=0;
$df=$hf-$lf;
$lastf=$hf;


while (1) {
	$free=freemem();
#	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time);
	($sec,$min,$hour,undef) = gmtime(time);
	if (abs($free-$lastfree)>$limit/50) {
		$lastfree=$free;
		if ($free<($limit)) {
			printf "%02d:%02d:%02d free memory: ".commify($free)." is 
below limit: ".commify($limit)."\n",$hour,$min,$sec;
		} else {
			printf "%02d:%02d:%02d free memory: 
".commify($free)."\n",$hour,$min,$sec;
			$skip=0;
		}
	}

	if ($free<($limit) && !$skip--) {
		$f=int($lf+$free*$df/$limit);
		$cmd="beep -l 50 -f $lastf; beep -l 50 -f $f; beep -l 50 -f $lf";
#		print "$cmd\n";
		`$cmd`;
		$lastf=$f;
		$skip=5;
	}

	sleep 1;
}

-- 
Low end Serverhousing ab 25 e inkl. 1x 11 e/GB, etc.: 
     
     http://bksys.at
     
     


_______________________________________________
crossfire-devel mailing list
     
     crossfire-devel at lists.real-time.com
     
     
     https://mailman.real-time.com/mailman/listinfo/crossfire-devel
     
     
    


More information about the crossfire mailing list