Problem with memory management
| From: | Alan Boudreault | Date: | Fri, 10 Oct 2008 19:08:30 +0000 |
| Subject: | Problem with memory management | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-281691@lists.php.net to get a copy of this message | ||
Hi all,
I'm wondering why PHP doesn't free my memory with this test code. The memory usage is always the same even if i unset my object. The Garbage collector seems to only free the memory at the end of the script.
Here's the php Scripts that i use for testing:
<?php
//dl("php_mapscript.so");
function test() {
$oShapeFile = ms_newShapefileObj(
"/opt/www/bdga/msp/data/bdga/BDGA_HYDRO_S_POLY.shp", -1);
echo "before getShape : ".memory_get_usage(true)."\n";
for ($i=0; $i<$oShapeFile->numshapes;$i++) {
$oShape = $oShapeFile->getShape($i);
$oShape->free();
unset($oShape);
$oShape = NULL;
}
echo "after getShape : ".memory_get_usage(true)."\n";
$oShapeFile->free();
unset($oShapeFile);
$oShapeFile = null;
echo "after free : ".memory_get_usage(true)."\n";} echo "start : ".memory_get_usage(true)."\n"; test(); echo "end : ".memory_get_usage(true)."\n"; ?> Output result: start : 262144 before getShape : 262144 after getShape : 11010048
after free : 11010048end : 11010048 I've also run valgrind to be sure that is not my extension that doesn't free its memory: $ valgrind --leak-check=full php -f shapeTest.php ==18730== LEAK SUMMARY:
==18730== definitely lost: 0 bytes in 0 blocks. ==18730== possibly lost: 0 bytes in 0 blocks. ==18730== still reachable: 240 bytes in 2 blocks. ==18730== suppressed: 0 bytes in 0 blocks.Thanks, Alan -- Alan Boudreault Mapgears http://www.mapgears.com