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

  • Home
  • SEARCH
  • 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 8967371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:13:41+00:00 2026-06-15T17:13:41+00:00

If I run the following PHP program on my computer echo memory_get_usage(); echo |;

  • 0

If I run the following PHP program on my computer

echo memory_get_usage();
echo "|";
echo memory_get_usage();
echo "|";
echo memory_get_usage();

I get the output

635048|635080|635080

From this, it appears the initial call to memory_get_usage is retaining 32KB of memory. I tried this without the echo statements

echo memory_get_usage();
echo memory_get_usage();
echo memory_get_usage();

and got a similar result

634504634536634536
//broken out 634504, 634536, 634536

While removing the echo statements reduced the overall memory usage of the script, there’s still the 32KB being retained after the initial call to memory_get_usage. Why is this?

I’ve tried this on multiple computers, and while the actual numbers differ, the gap remains the same.

If I look at (what I think is) the source of this function

//File: php-5.3.19/ext/standard/var.c
PHP_FUNCTION(memory_get_usage) {
    zend_bool real_usage = 0;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &real_usage) == FAILURE) {
        RETURN_FALSE;
    }

    RETURN_LONG(zend_memory_usage(real_usage TSRMLS_CC));
}

I don’t see anything in there that necessarily says “retain this variable in memory”. However, I haven’t written C seriously in years and I’ve never professionally hacked on the PHP source and my ability to trace execution is nill.

So, my question is, what’s retaining that 32KB of memory, and where does that happen in the PHP source code and/or how can I trace that from the memory_get_usage entry point.

  • 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-06-15T17:13:43+00:00Added an answer on June 15, 2026 at 5:13 pm

    This is probably the result of having to create output. Perhaps there’s some output buffering involved?

    At the command prompt:

    [charles@lobotomy /tmp]$ php --version
    PHP 5.4.9 (cli) (built: Nov 22 2012 12:59:04)
    Copyright (c) 1997-2012 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
        with Xdebug v2.2.0rc1, Copyright (c) 2002-2012, by Derick Rethans
    [charles@lobotomy /tmp]$ cat test.php
    <?php
    #echo '|';
    echo memory_get_usage();
    echo '|';
    echo memory_get_usage();
    echo '|';
    echo memory_get_usage();
    echo '|';
    
    [charles@lobotomy /tmp]$ php test.php
    227024|227056|227056|
    

    When test.php is modified to echo before the first measurement, we get

    [charles@lobotomy /tmp]$ cat test.php
    <?php
    echo '|';
    echo memory_get_usage();
    echo '|';
    echo memory_get_usage();
    echo '|';
    echo memory_get_usage();
    echo '|';
    
    [charles@lobotomy /tmp]$ php test.php
    |227192|227192|227192|
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I run following php file <?php $str = 'he; echo $str; ?> it
I have a php file 'run.php' which I'm running from the terminal. Within this
Trying to run the following command in php to run powershell command... the following
I'm attempting to run the following command in PHP (on Ubuntu): <?php if (exec(/home/johnboy/ffmpeg/ffmpeg
I'm using the following line of code to run my php file that I
Can not run following SQL from ant's sql task : BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =>
when I trying to run following code. var result = from c in db.brand
I run the following code from command line: public class MemoryTest { public static
I'm trying to get a PHP script to run every 30 minutes on my
Our customers run our php program on their own server. Some are Linux, some

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.