php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62684 PHP/DOMDocument: unset() does not release resources
Submitted: 2012-07-28 18:01 UTC Modified: 2012-07-28 19:50 UTC
From: jerico dot dev at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.3.15 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jerico dot dev at gmail dot com
New email:
PHP Version: OS:

 

 [2012-07-28 18:01 UTC] jerico dot dev at gmail dot com
Description:
------------
A complete problem description + sample code can be found here:

http://stackoverflow.com/questions/11703164/php-domdocument-unset-does-not-release-resources

Test script:
---------------
https://github.com/jerico-dev/ojs/blob/abc2af0f66c11664b7e917201fd707aa3307a1e0/plugins/generic/lucene/classes/SolrWebService.inc.php#L296

Expected result:
----------------
I expect unset() to release the memory resources that were used for the object.

Actual result:
--------------
unset() only releases a tiny amount of the resources actually used. See the debug output in http://stackoverflow.com/questions/11703164/php-domdocument-unset-does-not-release-resources

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-28 18:30 UTC] rasmus@php.net
-Status: Open +Status: Feedback
 [2012-07-28 18:30 UTC] rasmus@php.net
Sorry, a 1126-line reproduce script? I doubt any of us are going to read through 
that. Please simplify to a 10-15 line example that shows the problem you are 
having.
 [2012-07-28 18:54 UTC] jerico dot dev at gmail dot com
The link is not meant as a reproduction script but points to the actual source code + solutions I've tried. I tried a long time to better isolate the problem but I couldn't reproduce it in a smaller setting.

I appreciate any hint how I could go about further isolating the problem. I currently only rely on memory_get_usage() and xdebug_debug_zval(). Is there anything more I could do to identify what actually causes the problem? Does PHP provide some internal debugging messages that might indicate why unset() could not release the memory?

Here's what I already tried out:

* I checked that the reference count of $dom is exactly one immediately before the call to unset(): xdebug_debug_zval('dom') reports: dom: (refcount=1, is_ref=0)=class DOMDocument { }.

* I tried gc_enable() + gc_collect_cycles().

* I tried the solution proposed in http://stackoverflow.com/questions/8379829/domdocument-php-memory-leak

* I tried calling $dom->__destruct() before unset() but this will result in an error as DOMDocument apparently does not have a destructor.

* I recursively removed all nodes in the DOM before I unset the variable. It did not make the least difference.

* I tried setting the variable to null before re-using it: $dom = null

None of these showed any effect. I'm simply out of ideas how to simulate the problem in a way that makes it easier for you to reproduce it.
 [2012-07-28 18:54 UTC] jerico dot dev at gmail dot com
-Status: Feedback +Status: Open
 [2012-07-28 19:46 UTC] jerico dot dev at gmail dot com
-Status: Open +Status: Closed
 [2012-07-28 19:46 UTC] jerico dot dev at gmail dot com
I could track this down to a memory leak unrelated to DOMDocument. I'm still far from isolating the problem. But it's not what I thought. Sorry for the noise.
 [2012-07-28 19:50 UTC] rasmus@php.net
-Status: Closed +Status: Not a bug
 [2012-07-28 19:50 UTC] rasmus@php.net
ok
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC