Bug #54147 [Com]: debug_backtrace increases memory usage
Edit report at https://bugs.php.net/bug.php?id=54147&edit=1
ID: 54147
Comment by: twin at nightmail dot ru
Reported by: jacob at jacobweber dot com
Summary: debug_backtrace increases memory usage
Status: Open
Type: Bug
Package: Unknown/Other Function
Operating System: Red Hat Linux
PHP Version: 5.2.17
Block user comment: N
Private report: N
New Comment:
As you suppose, in PHP 5.3.6 option for skip args was added. And for function
debug_print_backtrace() too.
Previous Comments:
------------------------------------------------------------------------
[2011-03-03 03:58:43] jacob at jacobweber dot com
Description:
------------
Calling debug_backtrace(false) can lead to a huge increase in memory usage, if
it's called from within a function that was passed a huge string as an argument.
This is because the string will be duplicated in the "args" field of the result.
It would be nice to have another boolean argument to debug_backtrace, that would
tell it to skip the "args" field. This would be similar to the one that skips the
"object" field.
Or could the arguments be returned as references, so they don't increase memory
usage?
Test script:
---------------
function test($str) {
echo "before: ".round(memory_get_usage()/1024/1024, 2)." MB\n";
debug_backtrace(false);
echo "after: ".round(memory_get_usage()/1024/1024, 2)." MB\n";
}
test(str_repeat('a', 10000000));
Expected result:
----------------
before: 9.59 MB
after: 9.59 MB
(This is what I get if I remove the debug_backtrace() call.)
Actual result:
--------------
before: 9.59 MB
after: 19.12 MB
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54147&edit=1
Thread (3 messages)