From: tstarling Operating system: Linux PHP version: master-Git-2012-10-29 (Git) Package: XML related Bug Type: Bug Bug description:Allocation via libxml does not use PHP's per-request allocator
Description: ------------ Allocation via libxml does not use PHP's per-request allocator. So any memory used by libxml will not be accounted against memory_get_usage() or memory_limit. At Wikimedia we use libxml DOM trees to store wikitext parse trees, because they are more compact in memory than the equivalent pure-PHP data structures. When these parse trees are cached, the memory requirements can become excessive, and the memory is typically not returned to the system after request termination. Using xmlMemSetup() to set hook functions which use PHP's per-request allocation functions will allow us to more effectively monitor and limit the use of libxml in production. I've developed a patch and will submit it to GitHub as a pull request. Test script: --------------- $doc = new DOMDocument; for ( $i = 0; $i < 1000000 ; $i++ ) { $doc->appendChild($doc->createElement('foo')); } print memory_get_usage()."\n"; Expected result: ---------------- 312331440 (with debug and ZTS) Actual result: -------------- 694256 -- Edit bug report at https://bugs.php.net/bug.php?id=63380&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63380&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63380&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63380&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63380&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63380&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63380&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63380&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63380&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63380&r=support Expected behavior: https://bugs.php.net/fix.php?id=63380&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63380&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63380&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63380&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63380&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63380&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63380&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63380&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63380&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63380&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63380&r=mysqlcfg