php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41452 possible memory leak in DomNode->first_child
Submitted: 2007-05-21 06:45 UTC Modified: 2007-06-12 14:14 UTC
From: mike at netagi dot com Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 4.4.7 OS: Ubuntu Linux 6.06 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
18 - 4 = ?
Subscribe to this entry?

 
 [2007-05-21 06:45 UTC] mike at netagi dot com
Description:
------------
Directly after calling node->first_child the memory usage increases and does not drop. This might also be the case with has_child_nodes.

I've tried numerous test cases (as I am trying to keep memory consumption low) but have had no luck. I've tried using functions so the variables lose scope etc. Whatever gets created during the first_child can never be freed.

I understand that the Zend Engine may be caching some structures, however i have allocated 120 Meg to PHP4 CLI and it's still returning an out of memory error. If I disable first_child the script runs without any issues.



Reproduce code:
---------------
$doc = domxml_open_file("import_prod_cat.xml");
$xpath = $doc->xpath_new_context();
$obj = $xpath->xpath_eval('//import_catprod_link');
$nodeset = $obj->nodeset;
foreach($nodeset as $node ) {
        print "S1 " . memory_get_usage() . "\n";
        if( $node->has_child_nodes() ) {
                print " S2 " . memory_get_usage() . "\n";
                $child = $node->first_child();
                print " S3 " . memory_get_usage() . "\n";
                unset($child);
                unset($node);
                print " S4 " . memory_get_usage() . "\n";
        }
        print " S6 " . memory_get_usage() . "\n";
}
$doc->free();

Actual result:
--------------
S1 21202968
 S2 21203040
 S3 21204416
 S4 21204456
 S5 21204456

S1 21204456
 S2 21204456
 S3 21205184
 S4 21205224
 S5 21205224

S1 21205224
 S2 21205224
 S3 21205952
 S4 21205992
 S5 21205992

S1 21205992
 S2 21205992
 S3 21206720
 S4 21206760
 S5 21206760

... etc until it runs out of ram.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-12 14:14 UTC] rrichards@php.net
You need to upgrade to PHP 5 and ext/DOM.
This is just one of the reasons for the re-write of ext/domxml. Unset() and variable scope have no effect on the structures created by ext/domxml and they are not freed until the request is completed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 13:01:28 2024 UTC