note 99224 deleted from function.array-shift by salathe
| From: | salathe@php.net | Date: | Thu, 05 Aug 2010 08:24:05 +0000 |
| Subject: | note 99224 deleted from function.array-shift by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171383@lists.php.net to get a copy of this message | ||
Note Submitter: Aikar
----
Note that this function has a memory leak - it is not recommended to use in daemon applications that
run indefinitely.
Use the following to replace it as somewhat stated below
<?php
function array_shift_safe(&$arr)
{
$data = reset($arr);
$key = key($arr);
unset($arr[$key]);
return $data;
}
?>
I noticed this as my application slowly climbed in memory reaching up to 100+ MB (from 10mb
baseline), and simply changing the 1 section of code using array_shift to the above stopped the
leak.