simple_html_dom的PHP内存泄漏(在'parse()函数之后)

simple_html_dom的PHP内存泄漏(在'parse()函数之后),php,parsing,memory-leaks,simple-html-dom,Php,Parsing,Memory Leaks,Simple Html Dom,我使用的是简单的html dom 我发现在load函数中运行的parse函数会导致内存泄漏,但似乎无法找到原因 我尝试了$html->clear,取消设置$html,也清除了所有内容 做了这么多工作之后,记忆仍然不清晰 我的结果如下: 所以,我想知道我该怎么做才能清除幽灵的记忆 以下是我的测试代码: <? include('include/simple_html_dom.php'); ini_set('memory_limit', '128M'); echo 'memory =',r

我使用的是简单的html dom

我发现在load函数中运行的parse函数会导致内存泄漏,但似乎无法找到原因

我尝试了$html->clear,取消设置$html,也清除了所有内容

做了这么多工作之后,记忆仍然不清晰

我的结果如下:

所以,我想知道我该怎么做才能清除幽灵的记忆

以下是我的测试代码:

<? 
include('include/simple_html_dom.php');
ini_set('memory_limit', '128M');

echo 'memory =',round(memory_get_usage()/1000),' KB<br>';  
$url = 'http://www.marketwatch.com/';
$html = file_get_html($url);

foreach($html->find('div#mostpopular img') as $images){
    if($images->src !='')echo $images-> outertext ;
}

echo '<br>';

echo 'memory before clear =',round(memory_get_usage()/1000),' KB<br>';  
$html->clear;
$images->clear;

unset($html);
unset($images);

echo 'memory after clear =',round(memory_get_usage()/1000),' KB<br>'; 

echo 'memory before clean_all =',round(memory_get_usage()/1000),' KB<br>';
clean_all($GLOBALS);

echo 'memory after clean_all =',round(memory_get_usage()/1000),' KB<br>'; 



function clean_all(&$items,$leave = ''){
    foreach($items as $id => $item){
        if($leave && ((!is_array($leave) && $id == $leave) || (is_array($leave) && in_array($id,$leave)))) continue;
        if($id != 'GLOBALS'){
            if(is_object($item) && ((get_class($item) == 'simple_html_dom') || (get_class($item) == 'simple_html_dom_node'))){
                $items[$id]->clear();
                unset($items[$id]);
            }else if(is_array($item)){
                $first = array_shift($item);
                if(is_object($first) && ((get_class($first) == 'simple_html_dom') || (get_class($first) == 'simple_html_dom_node'))){
                    unset($items[$id]);
                }
                unset($first);
            }
        }
    }
}
?>
此外,我还将一些代码echo memory\u get\u用法放在simple\u html\u dom.php中。 经过几次尝试,我发现在第818行附近的加载函数中发生了一些事情:

// load html from string
function load($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT) {
    global $debugObject;
    // prepare
    $this->prepare($str, $lowercase, $stripRN, $defaultBRText);
    // strip out comments
    $this->remove_noise("'<!--(.*?)-->'is");
    // strip out cdata
    $this->remove_noise("'<!\[CDATA\[(.*?)\]\]>'is", true);

    // Per sourceforge http://sourceforge.net/tracker/?func=detail&aid=2949097&group_id=218559&atid=1044037
    // Script tags removal now preceeds style tag removal.
    // strip out <script> tags
    $this->remove_noise("'<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>'is");
    $this->remove_noise("'<\s*script\s*>(.*?)<\s*/\s*script\s*>'is");
    // strip out <style> tags
    $this->remove_noise("'<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>'is");
    $this->remove_noise("'<\s*style\s*>(.*?)<\s*/\s*style\s*>'is");
    // strip out preformatted tags
    $this->remove_noise("'<\s*(?:code)[^>]*>(.*?)<\s*/\s*(?:code)\s*>'is");
    // strip out server side scripts
    $this->remove_noise("'(<\?)(.*?)(\?>)'s", true);
    // strip smarty scripts
    $this->remove_noise("'(\{\w)(.*?)(\})'s", true);

    // parsing
    echo 'memory before parsing() =',round(memory_get_usage()/1000),' KB<br>';  
    while ($this->parse());
    echo 'memory after parsing()  =',round(memory_get_usage()/1000),' KB<br>';   
    // end          
    $this->root->_[HDOM_INFO_END] = $this->cursor;
    $this->parse_charset();

}

没有正确清除dom对象,忘记了括号:

$html->clear();
$images->clear();
下面是一段更正后的代码

以下是输出:

此外,如果您有任何检测到的bug或可能的补丁,请随时向我们报告