note 99224 added to function.array-shift

From: Date: Wed, 04 Aug 2010 20:39:19 +0000
Subject: note 99224 added to function.array-shift
Groups: php.notes 
Request: Send a blank email to php-notes+get-171369@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 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. ---- Server IP: 192.41.42.26 Probable Submitter: 69.34.157.32 ---- Manual Page -- http://www.php.net/manual/en/function.array-shift.php Edit -- https://master.php.net/note/edit/99224 Del: integrated -- https://master.php.net/note/delete/99224/integrated Del: useless -- https://master.php.net/note/delete/99224/useless Del: bad code -- https://master.php.net/note/delete/99224/bad+code Del: spam -- https://master.php.net/note/delete/99224/spam Del: non-english -- https://master.php.net/note/delete/99224/non-english Del: in docs -- https://master.php.net/note/delete/99224/in+docs Del: other reasons-- https://master.php.net/note/delete/99224 Reject -- https://master.php.net/note/reject/99224 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171369) next »