'Cleaning up memory'

Hi,

I got a couple of messages telling me that making 7000+ objects ( results from a databasequery ) was a little bit too much for our PHP-engine. Looking around on the net I see the suggestion “Increase the amount of memory PHP can use” but I’d rather just have 1 object in memory.
However, when I try to unset() my object and reuse it for new data, I still get the ‘exceeding memory bla’ message.
So my question is basically, how do I clean up my memory?

Thanks.

I don’t think unset() actually releases the memory the variable held - at least not until php’s garbage collection runs but setting a value to NULL will actually force a release (I seem to recall reading that somewhere).

Shrugs…

Hey thanks! I’m going to try that.

:smiley:

Actually…looks like I’m wrong. I started getting more curious on this and ran a couple of tests. This is on php 5.3.10

[php]
echo memory_get_usage() . PHP_EOL;
$array = array();

for ($i=0;$i < 10000; $i++) {
$array[] = rand();
}

echo memory_get_usage() . PHP_EOL;

unset($array);

echo memory_get_usage() . PHP_EOL;[/php]

I get:

634384
2766376
634656

Changing unset($array) to $array = NULL gives almost the same results…

I’m curious…as a Java programmer, I don’t understand what this means:

$array[] = rand();

Builds an array with random numbers… sort of like (in php):
[php]$myArray = array(‘1’,‘42’,‘13’,7’);[/php]

…and forgive my horrible Java code that follows :wink:

public static main(array myArray)
{
    Random rand = new Random();
    int myArray[] = new int[20];
    for (int i = 0; i < 20; i++){
        myArray[i] = rand.nextInt(10);
    }
}

grin ;D Horrible Java Code? Looks fine to me.
( But admitted I can only write horrible java code… Not so much as that the code is horrible but I find NoVa quite horrible ; ) )

Sponsor our Newsletter | Privacy Policy | Terms of Service