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 8378347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:54:37+00:00 2026-06-09T15:54:37+00:00

I tried to compare the constants and variables used in memory, but found a

  • 0

I tried to compare the constants and variables used in memory, but found a strange phenomenon.

test code:

<?php
var_dump( memory_get_usage() );  // int(129100)
// I don't understand: I don't do someting but why there has the changed
var_dump( memory_get_usage() );  // int(129156)  
var_dump( memory_get_usage() );  // int(129156)

define('hello', 'WORLD');
// why here hasn't changed
var_dump( memory_get_usage() );  // int(129156)

$hello = 'WORLD';
var_dump( memory_get_usage() );  // int(129304)
?>
  • 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-09T15:54:38+00:00Added an answer on June 9, 2026 at 3:54 pm

    First: PHP has a lot of memory leaks. This means, it does allocate memory somewhere, but doesn’t free it. So don’t be afraid seeing such effects. But this time it’s probably something else:

    Look at this example:

    <?php
    
    $data = array(0,0,0,0);
    $data[0] = memory_get_usage();
    $data[1] = memory_get_usage();
    
    echo $data[0];
    echo "\n";
    echo $data[1];
    echo "\n";
    
    $data[2] = memory_get_usage();
    echo $data[2];
    echo "\n";
    $data[3] = memory_get_usage();
    echo $data[3];
    echo "\n";
    
    ?>
    

    The output will be like:

    626464
    626464
    626528
    626528
    

    You see that it changes after the first call to “echo”, which must be allocating memory for the output buffer or something like that. Maybe its internally using printf(buffer, “…”, …) to generate the string thats send to the standard output. This string is reused in later calls and just resized to a longer buffer if needed.

    Your call to var_dump indirectly uses the echo function and probably also uses some internal buffer, thats allocated at the first call.

    Solution: To measure things more accurate you should call each output function once before your “measurements” or never call them before the final output of your results.

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

Sidebar

Related Questions

I've tried several methods to compare years in a date, but each time I'm
My string comparison doesnt work.I tried compare,equals ,= and all of these methods doesnt
I have tried several mySQL queries to compare a column of dates stored as
I tried profiling the EIG function on MATLAB and NumPy to compare performance on
tried uncommenting pam_limits.so from the pam.d directory but no luck. Basic PAM seems to
Tried searching the site, but cannot find an answer to my problem: Lets say
Tried a bunch of things but I can't get it to work consistently amid
I tried to compare RedGate performance profile on two different machines and to my
i tried to compare my java web app behaviour on 32 bit windows and
Has anyone tried both? I started with nicEditor but am considering switching to TinyMCE

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.