PHP/DOMDocument:unset()不释放资源 [英] PHP/DOMDocument: unset() does not release resources
问题描述
我有一个变量$dom
,其中包含PHP的DOMDocument实例.正在循环中设置和取消设置此变量.
unset($dom)
不会释放内存,但是:memory_get_usage(false)
报告只有大约10MB的700B被释放. memory_get_usage(true)
报告在unset()
之前和之后的内存使用量完全相同.
我尝试了以下操作:
-
我检查了$ dom的引用计数是否恰好在调用
unset()
之前正好是一个:xdebug_debug_zval('dom')
报告:dom:(refcount = 1,is_ref = 0)= class DOMDocument {}. /p> -
我尝试了 DOMDocument PHP内存泄漏中提出的解决方案,但这是为了无济于事.
-
我尝试了
gc_enable()
+gc_collect_cycles()
.但这也无济于事. -
我尝试在
unset()
之前调用$dom->__destruct()
,但这会导致错误,因为DOMDocument显然没有析构函数. -
在取消设置变量之前,我以递归方式删除了DOM中的所有节点.没什么区别.
-
在重新使用变量之前,我尝试将其设置为null:
$dom = null
现在我没主意了……有人建议我还可以尝试调试或解决这个问题吗?
-
php -v报告带有Suhosin-Patch(cli)的5.3.10-1ubuntu3.2
-
前几次迭代的输出为:
before object creation: 19292296 after object creation: 29849832 before unset: 30055232 after unset: 30054448 before object creation: 29849592 after object creation: 39858840 before unset: 40079920 after unset: 40079136 before object creation: 39858272 after object creation: 49923216 before unset: 50136448 after unset: 50135664
这应该释放$ dom中的内存存储.
$dom = null;
I've got a variable $dom
that contains an instance of PHP's DOMDocument. This variable is being set and unset within a loop.
unset($dom)
will not release memory, though: memory_get_usage(false)
reports that only 700B of about 10MB got released. memory_get_usage(true)
reports the exact same amount of memory usage before and after unset()
.
I tried the following:
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 the solution proposed in DOMDocument PHP Memory Leak but this was to no avail.
I tried
gc_enable()
+gc_collect_cycles()
. But this did not help either.I tried calling
$dom->__destruct()
beforeunset()
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
Now I'm out of ideas... Anybody got a suggestion what else I could try to debug or solve this problem?
Edit:
php -v reports 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli)
The source code can be seen here: https://github.com/jerico-dev/ojs/blob/dev/plugins/generic/lucene/classes/SolrWebService.inc.php#L256
The output of the first few iterations is:
before object creation: 19292296 after object creation: 29849832 before unset: 30055232 after unset: 30054448 before object creation: 29849592 after object creation: 39858840 before unset: 40079920 after unset: 40079136 before object creation: 39858272 after object creation: 49923216 before unset: 50136448 after unset: 50135664
This should release the memory store in $dom.
$dom = null;
这篇关于PHP/DOMDocument:unset()不释放资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!