Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4024886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:46:38+00:00 2026-05-20T10:46:38+00:00

When trying to trace some memory issues in PHP, I noticed that debug_backtrace() ,

  • 0

When trying to trace some memory issues in PHP, I noticed that debug_backtrace(), which I call in my logging code, seemed to be using a lot of memory.

In most cases, the following code prints something like 0.02 MB. But in one case, it prints 171.85 MB!

$before = memory_get_usage();
$backtrace = debug_backtrace(false);
$after = memory_get_usage();
echo round(($after - $before)/1024/1024, 2)." MB";

My question is, does this mean that debug_backtrace is actually using that much memory? Or could something else be happening, like garbage collection, that messes up the return value from memory_get_usage?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:46:39+00:00Added an answer on May 20, 2026 at 10:46 am

    Okay, I think I figured it out. I printed out the backtrace, and the "args" array was huge. This is because I was passing around some enormous strings. I guess it’s making copies of them (instead of references) when returning the results.

    For example:

    function test($str) {
        test2($str);
    }
    function test2($str) {
        test3($str);
    }
    function test3($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));
    

    Try this with and without the debug_backtrace() call. With it, the memory usage is increased by about 28 MB. It’s only cleared when test3() returns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using xdebug to trace some code to see how much memory it
I was trying to compile some code that uses Boost (1.49), with Clang(& libc++)
I am trying to script some code that will search a specified folder on
I am trying to write an TUI bandwidth trace application which on query can
I'm trying to use the following code to get all trace data for the
I'm trying to find a simple way to call a NSLog to trace myPoint
I'm trying to track down an issue in our MFC code that looks like
I'm trying to track down a memory leak in a java process, using jmap
I recently posted a question here about some memory issues I was having. I've
I'm trying to trace some SQL in Microsoft Server. I came across a join

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.