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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:06:46+00:00 2026-06-10T13:06:46+00:00

I was trying to check the memory_get_peak_usage() method, I try to create a objects

  • 0

I was trying to check the memory_get_peak_usage() method, I try to create a objects dynamically inside a for loop, and tried to print the memory used by my php script. here is the code :-

$objArr = array();
for( $i=1; $i<=100; $i++ ){
 echo "creating employee == " . memory_get_peak_usage()/1024 . " Kbs\n";
 $objArr[$i] = new CEmployee();
}
exit;

And here is the result that confused me :-

creating employee == 4156.84375 Kbs
creating employee == 6619.640625 Kbs
creating employee == 6619.640625 Kbs
creating employee == 6619.640625 Kbs
...
...(up to 40 lines from 2nd line same result as above and then from 41 line changed)

creating employee == 6623.5546875 Kbs
creating employee == 6631.234375 Kbs
creating employee == 6638.9140625 Kbs
creating employee == 6646.59375 Kbs
creating employee == 6654.2734375 Kbs
creating employee == 6661.953125 Kbs
creating employee == 6669.6328125 Kbs
creating employee == 6677.3125 Kbs
creating employee == 6684.9921875 Kbs
....
....

I am not getting how php is allocating memory to the objects. I am running the script on command line interface on windows 7

UPDATED CODE:-

gc_collect_cycles();
for( $i=1; $i<=100; $i++ ){
echo "creating employee == " . memory_get_usage()/1024 . " Kbs\n";
$objArr[$i] = new CEmployee();
    $objArr[$i]->setEmployeeNumber($i);
}exit;
  • 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-10T13:06:48+00:00Added an answer on June 10, 2026 at 1:06 pm

    As you can see by this it does increase memory usage:

    http://codepad.org/RApsrlXh

    However you might have data ready for garbage collection, hence when you create a new CEmployee it might be using that space.

    Try running gc_collect_cycles() before your loop to and use memory_get_usage() to get a more accurate reading.

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

Sidebar

Related Questions

I'm trying to check a checkbox, i've tried doing the following :- $('#someId').attr('checked','checked'); $('#someId').attr('checked',
I am trying to check the security of my MVC application. When I try
i'm trying to check the output of a cURL. <?php $ch = curl_init(); curl_setopt($ch,
gcc 4.5.1 c89 I am trying to free some memory. However, when I check
I am trying to run my program to check memory leaks in my program
I'm trying to dynamically add Images to a ScrollView. Before adding I check if
I am trying to check a series of buttons to see if they have
I'm trying to check if a file exists. If I use this: NSData *data
I am trying to check the following and all throw an out of bounds
I am trying to check if an email address already exists in a user

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.