php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54147 debug_backtrace increases memory usage
Submitted: 2011-03-03 03:58 UTC Modified: 2013-03-02 18:10 UTC
Votes:3
Avg. Score:2.7 ± 1.2
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: jacob at jacobweber dot com Assigned: dlsniper (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.2.17 OS: Red Hat Linux
Private report: No CVE-ID: None
 [2011-03-03 03:58 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-12 09:41 UTC] twin at nightmail dot ru
As you suppose, in PHP 5.3.6 option for skip args was added. And for function 
debug_print_backtrace() too.
 [2013-03-02 18:10 UTC] dlsniper@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

This has been fixed as of PHP 5.3.6
 [2013-03-02 18:10 UTC] dlsniper@php.net
-Status: Open +Status: Closed -Type: Bug +Type: Feature/Change Request -Assigned To: +Assigned To: dlsniper
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 21:01:29 2024 UTC