|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-11-12 09:19 UTC] xczgamer at gmail dot com
[2014-11-12 12:28 UTC] ryan dot brothers at gmail dot com
[2014-11-12 17:43 UTC] rasmus@php.net
-Status: Open
+Status: Not a bug
[2014-11-12 17:43 UTC] rasmus@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 00:00:02 2025 UTC |
Description: ------------ In the below example, the foreach in the global scope doesn't use any extra memory, but the memory usage almost doubles from doing the foreach inside test_function. Is there a reason that so much extra memory is used? I was expecting it not to use any extra memory as the foreach is done using a reference for each array element. Test script: --------------- <?php function test_function($rows) { echo memory_get_usage(true)."\n"; foreach ($rows as &$row) { } unset($row); echo memory_get_usage(true)."\n"; }; $rows = range(1, 10000); echo memory_get_usage(true)."\n"; foreach ($rows as &$row) { } unset($row); echo memory_get_usage(true)."\n"; test_function($rows); Expected result: ---------------- 1835008 1835008 1835008 1835008 Actual result: -------------- 1835008 1835008 1835008 3407872