- memory_get_usage: documentation ( source)
- rand: documentation ( source)
<?php
function get_objects() {
$array = array();
for ($i=0; $i<5000; $i++) {
$object = new stdClass();
$object->a = rand();
$object->b = rand();
$object->c = rand();
$object->d = rand();
$object->e = rand();
$array[] = $object;
}
return $array;
}
$results = array();
for ($i=0; $i<30; $i++) {
$results = get_objects();
echo memory_get_usage(true) . "\n";
// assigning empty array fixes the problem
// $results = array();
}