note 99224 modified in function.array-shift by danbrown

From: Date: Wed, 04 Aug 2010 20:49:55 +0000
Subject: note 99224 modified in function.array-shift by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171370@lists.php.net to get a copy of this message
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. --was-- 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 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. http://php.net/manual/en/function.array-shift.php

« previous php.notes (#171370) next »