|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
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
A complete problem description + sample code can be found here:

Test script:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-28 18:30 UTC]
-Status: Open +Status: Feedback
 [2012-07-28 18:30 UTC]
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 
 [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

* 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]
-Status: Closed +Status: Not a bug
 [2012-07-28 19:50 UTC]
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 22:01:29 2024 UTC