|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30911 DOM XML Extension xpath_new_context memory leak
Submitted: 2004-11-26 15:38 UTC Modified: 2004-11-27 12:12 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: slaporte at eurocortex dot fr Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 4.3.9 OS: red hat
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: slaporte at eurocortex dot fr
New email:
PHP Version: OS:


 [2004-11-26 15:38 UTC] slaporte at eurocortex dot fr
i'm using php and dom xml 
i encounter a memory leak 
the destructor of xpath context 
is not called 
i'm using 4_3_9 version 
i put some fprintf(stderr, ...) into the destructor 
and it never go inside 
the destructor was registered with "xpathcontext" 
le_xpathctxp = zend_register_list_destructors_ex(php_free_xpath_context, NULL, "xpathcontext", module_number); 

the class with "XPathContext" 
INIT_OVERLOADED_CLASS_ENTRY(ce, "XPathContext", php_xpathctx_class_functions, NULL, NULL, NULL); 

i try to make both lowercase 
but it is changing nothing 

the test script is very simple 
and when you run it
and the process grow and grow and grow .... 

i add a function free to xpathcontext object
that function calls the destructor
then the memory is released

but i would prefer that the destructor be called naturally

Reproduce code:
function StringToXml($sXml) { 
$oDom = domxml_open_mem($sXml); 
$oCtx = $oDom->xpath_new_context(); 

$s = getFile("test.xml"); 
for($n=200000; $n--;) { 
echo "$n<br/>"; 

Expected result:
php process should not grow, memory should be released

Actual result:
php process grow


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-26 18:11 UTC]
is the memory released after the request finishes? Or does it stay there.

 [2004-11-26 18:20 UTC] slaporte at eurocortex dot fr
Thank you for your reply
the script is started using php command line
"php -f test.php"
at the end of the script the php process die and the memory is then released
 [2004-11-26 18:29 UTC] slaporte at eurocortex dot fr
This script is a part of a big script that is parsing 100000 TEXT fields (read from records in a mysql database) 
the fields contains XML.
30 seconds after starting the process it takes 300M in memory then linux killed the process before it ends.
The memory is then released and available to the system but my process die before having finished.
Thank you for your help
 [2004-11-27 12:05 UTC]
There are no destructors called on unset() in PHP 4, as far as I know (at least not in the dom extension). That's the reason, why the $doc->free() method was implemented.

I recommend switching to PHP 5, as the problem should be fixed there. 

 [2004-11-27 12:12 UTC]
?hm, "Wont fix". Not "Closed" as status..
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 12 18:01:29 2024 UTC