Take a look at the following code,
for($i = 0; $i < 50; $i++) {
$instance[$i] = new SomeClass();
//do something with $instance[$i];
}
This is a common quirk for PHP developers relying too much on PHP's built-in garbage collector. But as you can see if the instantiated class is too big, it will rapidly consume your memory limit and cause the application to crash.
Anyway, the fix is simple. Just destroy the object for every iteration.
for($i = 0; $i < 50; $i++) {
$instance[$i] = new SomeClass();
//do something with $instance[$i];
unset($instance[$i]);
}
No comments:
Post a Comment