Hi! Just stumbled upon a strange behaviour when iterating over DOMNodeLists. Before I open a bug report I'd like to ask if anyone can comment on this issue, maybe it's the excpected behaviour.
Consider the following small script: <?php fgets( STDIN ); $xml = <<<XML <?xml version="1.0" ?> <root> <node>x</node> <node>x</node> <node>x</node> </root> XML; $dom = new DOMDocument(); $dom->loadXML( $xml ); $xpath = new DOMXPath( $dom ); while ( true ) { # 1. memory eater... $link_object_list = $xpath->query( '//node' ); # 2. constant memory usage #$link_object_list = $dom->getElementsByTagName( 'node' ); foreach ( $link_object_list as $value ) { while ( true ) { $link = $link_object_list->item( 0 ); } } } ?> Strange thing is, if the DomNodeList is produced by the xpath query, the script eats memory. If I use getElementsByTagName to get the list memory usage is constant. $value holds the object handle for the first NodeItem. If another list element is accessed (e.g. the second one) the usage is constant as well (both cases). Seems as if there's something strange going on with object handles and / or wrong garbage collection. Or maybe I'm just confusing things here ;) Any comments? Greetings Nico