soma56 Posted July 12, 2010 Share Posted July 12, 2010 S.C. Chen created a great script known as PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net). It allows for easy manipulation of html. While running the script through a loop I've been experiencing major memory issues. I soon discovered that the script has a function that cleans up the memory. Great! Here's a tidbit from the Author: Due to php5 circular references memory leak, after creating DOM object, you must call $dom->clear() to free memory if call file_get_dom() more then once. Example: $html = file_get_html(...); // do something... $html->clear(); unset($html); This seems simple enough. I'm converting the html to plaintext through his script so I figured this would work: include('simple_html_dom.php'); $html = file_get_html(...); // do something... $text = str_get_dom($html)->plaintext; // do something... $text->clear(); unset($html); I receive the following error "Call to a member function clear() on a non-object in...". This appears to be the results of failing to include the script that contains the function yet other aspects of the script work correctly. This is based on my 2 months of learning php anyways. I suspect I'm not calling the function correctly $text->clear(); or is there something I'm missing? Link to comment https://forums.phpfreaks.com/topic/207531-circular-references-memory-leak-fatal-error-call-to-a-member-function/ Share on other sites More sharing options...
AbraCadaver Posted July 12, 2010 Share Posted July 12, 2010 clear() is a function of the $html object, not $text. Try $html->clear(); Link to comment https://forums.phpfreaks.com/topic/207531-circular-references-memory-leak-fatal-error-call-to-a-member-function/#findComment-1085013 Share on other sites More sharing options...
soma56 Posted July 12, 2010 Author Share Posted July 12, 2010 I appreciate the quick response. I tried that and received the same results. Googling this references a lot of SQL issues. I did find one line that I'm thinking might relate and I'm trying to comprehend: Your constructor for the class is not setting the object member variable correctly, so it remains a null reference, which causes the error. There are two 'clear' functions within the Simple HTML DOM Parser script: class simple_html_dom_node { // clean up memory due to php5 circular references memory leak... function clear() { $this->dom = null; $this->nodes = null; $this->parent = null; $this->children = null; } } class simple_html_dom { function clear() { foreach($this->nodes as $n) {$n->clear(); $n = null;} if (isset($this->parent)) {$this->parent->clear(); unset($this->parent);} if (isset($this->root)) {$this->root->clear(); unset($this->root);} unset($this->doc); unset($this->noise); } } Link to comment https://forums.phpfreaks.com/topic/207531-circular-references-memory-leak-fatal-error-call-to-a-member-function/#findComment-1085015 Share on other sites More sharing options...
soma56 Posted July 12, 2010 Author Share Posted July 12, 2010 It seems that because I'm using cURL to get the url it's conflicting with the 'file_get_html' function. Link to comment https://forums.phpfreaks.com/topic/207531-circular-references-memory-leak-fatal-error-call-to-a-member-function/#findComment-1085092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.