Re: PHP Memory Management

From: Date: Mon, 04 Aug 2008 04:02:57 +0000
Subject: Re: PHP Memory Management
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-277654@lists.php.net to get a copy of this message
is it possible because you can assign $func = foo and call $func() and it will call foo(), maybe that its creating an endless loop of assigning the function to itself? On Sun, Aug 3, 2008 at 11:17 AM, brian <php@logi.ca> wrote: > Waynn Lue wrote: > >> I've been running the script below: >> >> <?php >> $appIds = getLotsOfAppIds(); >> foreach ($appIds as $appId) { >> echo "$appId\n"; >> //echo memory_get_usage() . "\n"; >> try { >> $getBundles = getBundles($appId); >> $numBundles = count($registeredBundles); >> echo $numBundles . "\n"; >> continue; >> } >> } >> ?> >> >> And I get PHP Fatal Error: Allowed Memory Size Exhausted after it runs for >> a >> bit. Looking at the memory usage, it's because $getBundles (an array) is >> huge, and keeps growing. What I'm confused by is why setting it to >> something else in the next iteration of the foreach loop doesn't free the >> previously allocated array, since there shouldn't be any more references >> to >> it. I've worked around it by explicitly calling unset($getBundles), but >> just wanted to understand why it's working the way it does. >> >> > Aside from on the 1st iteration, each time getBundles() is called, it > creates an array within its own scope. Until PHP assigns the returned array > to $getBundles, there are two in memory. Maybe that's the problem. > > I don't know how you can stand naming structures or variables the same as > functions, btw. That would drive me nuts. Where is this $registeredBundles > coming from? Perhaps you meant: > > $registeredBundles = getBundles($appId); > > b > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- http://twit.tv - What I listen to All Week

« previous php.general (#277654) next »