Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.0.0

Bug #12666 memory leak when instantiating new parsers?
Submitted: 2007-12-11 23:00 UTC
From: silver Assigned:
Status: Open Package: XML_HTMLSax3 (version 3.0.0)
PHP Version: 5.2.4 OS: Debian GNU/Linux 4.0
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


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 !
Your email address:
MUST BE VALID
Solve the problem : 50 - 39 = ?

 
 [2007-12-11 23:00 UTC] silver (Silver Harloe)
Description: ------------ instantiating new parsers repeatedly leaks memory, even if the parsers are unset Test script: --------------- require_once 'XML/HTMLSax3.php'; function parse($doc) { static $parser; if (!isset($parser)) $parser = new XML_HTMLSax3(); $parser->parse($doc); } function parse2($doc) { $parser = new XML_HTMLSax3(); $parser->parse($doc); unset($parser); } $s = "blah"; $start_mem = memory_get_usage(true); for ($i = 0; $i < 1000; $i++) parse($s); $mem_diff = memory_get_usage(true) - $start_mem; print "1000 iterations with static parser, memory diff " . (memory_get_usage(true) - $start_mem) . "\n"; $start_mem = memory_get_usage(true); for ($i = 0; $i < 1000; $i++) parse2($s); $mem_diff = memory_get_usage(true) - $start_mem; print "1000 iterations with new parser each time, memory diff " . (memory_get_usage(true) - $start_mem) . "\n"; Expected result: ---------------- 1000 iterations with static parser, memory diff 0 1000 iterations with new parser each time, memory diff 0 Actual result: -------------- 1000 iterations with static parser, memory diff 0 1000 iterations with new parser each time, memory diff 4456448

Comments

 [2007-12-12 19:30 UTC] silver (silver Harloe)
my coworker discovered that if you were make a destructor which unsets the members $state_parser->handler_default and $parser->state_parser, this would fix the problem (in php5)
 [2008-05-05 13:18 UTC] doconnor (Daniel O'Connor)
Can you retry this with php 5.2.6?
 [2008-10-26 13:36 UTC] doconnor (Daniel O'Connor)
Ok, I'm seeing the same thing with php 5.2.4; but it sounds to me like http://www.exponetic.com/blog/blog/2004/09/13/php-5-garbage-collection/ ; which is a bit of a pain to fix properly (and I'm keen to play wait-and-see for 5.3+).