Edit report at http://bugs.php.net/bug.php?id=54120&edit=1
ID: 54120
User updated by: ikaos at gmx dot fr
Reported by: ikaos at gmx dot fr
Summary: Impossible to freed memory complety after call to
Xpath() method.
Status: Bogus
Type: Bug
Package: SimpleXML related
Operating System: Linux CentOS 5.5 x86_64
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
Thank you for this quick answer. I red these informations on
http://xmlsoft.org/xmlmem.html before.
But there is something strange (perhaps I don't understand how kernel
release memory), after freeing memory I could understand the kernel
doesn't release immediatly the memory, but in that case there is a big
problem for me, for exemple I use pcntl and try to fork my script after
using xpath and releasing memory, and it fails. If I don't use xpath()
it works.
I think I understand there is a command malloc_trim, but it doesn't
exists directly from PHP. Is there a workaround I could use ?
Second question, It seems that memory_get_usage returns the memory used
by PHP, after freeing memory (after xpath()) I still have more memory
used than before using xpath(). Is it normal or still related to the way
the kernel works ?
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2011-03-01 20:54:30] [email protected]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
Memory is freed. http://xmlsoft.org/xmlmem.html you can read how memory
is managed
and might not be returned immediately to the kernel.
------------------------------------------------------------------------
[2011-02-28 15:58:00] ikaos at gmx dot fr
Description:
------------
---
>From manual page: http://www.php.net/simplexmlelement.xpath
---
Test script:
---------------
<?php
$sxe = NULL; $nodes = NULL;
print("Without call to xpath method : " . PHP_EOL);
print("Memory before SXE : " . memory_get_usage() . PHP_EOL);
$sxe = new SimpleXMLElement("large_file.xml", 0, TRUE);
$sxe = NULL; $nodes = NULL;
print("Memory after freed memory : " . memory_get_usage() . PHP_EOL .
PHP_EOL);
$sxe = NULL; $nodes = NULL;
print("Calling xpath method : " . PHP_EOL);
print("Memory before SXE : " . memory_get_usage() . PHP_EOL);
$sxe = new SimpleXMLElement("large_file.xml", 0, TRUE);
$nodes = $sxe->xpath('/ITEMS/ITEM');
$sxe = NULL; $nodes = NULL;
print("Memory after freed memory : " . memory_get_usage() . PHP_EOL .
PHP_EOL);
// short sleep, time to launch 'ps aux'
sleep(10);
?>
Expected result:
----------------
When I unset (or set to NULL) the result of the Xpath() method ($nodes
in the example), I expect memory will be completly freed. It's not the
case.
I tried, to recursively unset each element from $nodes and I got the
same result.
Actual result:
--------------
Result of the test script :
Without call to xpath method :
Memory before SXE : 625736
Memory after freed memory : 625904
Calling xpath method :
Memory before SXE : 625904
Memory after freed memory : 1608944
memory_get_usage says that few kilos octets of memory are still used,
but in reality several thousand mega octets are still used.
# ps aux | grep test.php
me 28859 83.4 48.3 *1119908* *996056* pts/3 S+ 15:30 0:08 /bin/php
test.php
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54120&edit=1