php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53415 memory_get_usage is inaccurate
Submitted: 2010-11-26 14:36 UTC Modified: 2010-11-27 04:03 UTC
From: thepixeldeveloper at googlemail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3 OS: Linux durango 2.6.36-020636rc8-g
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: thepixeldeveloper at googlemail dot com
New email:
PHP Version: OS:

 

 [2010-11-26 14:36 UTC] thepixeldeveloper at googlemail dot com
Description:
------------
memory_get_usage does not work correctly with reflection calls such as invoke.

Test script:
---------------
<?php
 
class HelloWorld
{
 public function sayHelloTo($name)
 {
  $s = memory_get_usage();
 
  $something = str_repeat($name, pow(1024, 2));
 
  echo 'Inside: ';
  echo memory_get_usage() - $s.PHP_EOL;
 }
}
 
$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHelloTo');
 
$s = memory_get_usage();
 
 $reflectionMethod->invoke(new HelloWorld(), 'a');
 
echo 'Outside: ';
echo memory_get_usage() - $s;

Expected result:
----------------
Inside: 1048760
Outside: 1048760

Actual result:
--------------
Inside: 1048760
Outside: 92

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-27 04:03 UTC] scottmac@php.net
-Status: Open +Status: Bogus
 [2010-11-27 04:03 UTC] scottmac@php.net
$something is destroyed when the scope is lost and the memory is free'd back to 
PHP to use again. Hence the low value outside.

Maybe you're looking for memory_get_peak_usage()
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Sep 23 00:00:02 2025 UTC