8

According to my xdebug output, is_array() leaks the amount of memory that gets passed to it as an argument. If I pass it a large array, it leaks a ton of memory just in order to check if it's an array.

Is there a workaround for this?

   17.4313   21858520   +70004                   -> is_array() [...]/app/app_model.php:526

Here's the code snippet that causes the leak:

        $ret = $this->behaviors[$b[$i]]->afterFind($this, $results, true);
        if (is_array($ret)) {
            $results = $ret;
        }

I'm running this on Linux (Ubuntu 9.04)

PHP: 5.3.2

xdebug: 2.0.5

uname -a gives me this:

Linux linux8 2.6.28-19-server #64-Ubuntu SMP Wed Aug 18 21:57:33 UTC 2010 i686 GNU/Linux

6
  • 2
    I think you forgot to specify PHP version and your code, which should be relevant to this leak. insertPHPJoke() Commented Sep 8, 2010 at 14:58
  • 5
    What do you mean "leak memory"? The memory is not reclaimed after the call? Commented Sep 8, 2010 at 15:09
  • 1
    Is I cannot reproduce it here: have you got xdebug.collect_params enabled, and what happens if you disable it? Commented Sep 8, 2010 at 15:55
  • After checking: no, collect params doesn't seem the culprit, and I cannot reproduce it. Some version numbers (PHP & xdebug), OS & a specific test script could be required. Commented Sep 8, 2010 at 16:03
  • Just look in the source code if you want to know what happens: type.c:201 PHP 5.3.2 Commented Sep 8, 2010 at 17:04

2 Answers 2

5

My first reaction:

Select isn't broken.

My second reaction:

You can conclude three things:

  • a widely spread piece of software (is_array) is broken - You are the first one to notice
  • xdebug is broken reports a leak where there is none
  • xdebug and PHP don't work together nicely as it concerns memory management

A widely spread and used function is most often not the problem. Try to narrow down the occurence of the 'xdebug leak report' by running simpler code:

$arr = array_fill( 0, 10000, "content" );
$mallocbytes=true;// set to true to get process 
$usage=memory_get_usage(!$mallocbytes);
for( $i=0; $i!=1000000; $i=$i+1) { 
   is_array($arr); 
   $newusage=memory_get_usage(!$mallocbytes);
   if( $newusage != $usage ) {
      print( "diff after $i'th is_array: ".($newusage-$usage)."\n" );
   }
   $usage=$newusage;
}

Take a look at the actual memory consumption of your PHP runtime. I bet it won't grow.

Sign up to request clarification or add additional context in comments.

1 Comment

After running your example, I believe that the problem is in xdebug and not in the PHP runtime.
0

http://php.net/manual/en/function.gettype.php may be a suitable work-around. The best path is to submit a patch that fixes the bug, but that may be outside the scope of your contract.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.