Question

Possible Duplicate:
php/symfony/doctrine memory leak?

I need to know if there is a way to destroy an object in symfony 1.4, because I have a cicle for that insert on database.

foreach ($array_data as $payroll_employee)
{
  $discounts = new PayrollDiscounts();
  $discounts->setPayrollId($payroll_id);
  $discounts->save();
  $discounts->free(TRUE);
  unset($discounts);
}

and display this Error:

Fatal error: Allowed memory size of 134217728 bytes exhausted

So I need to know a way to deliver memory.

Was it helpful?

Solution 3

I have find the solution in these link:

php/symfony/doctrine memory leak?

Thanks for all your advices!

OTHER TIPS

Using unset() will specifically free the memory associated with the variable, however I doubt that the setting of the $discounts variable is where you are running into your memory allocation issue, as it would have been overwritten with each pass of the loop. Is $array_data itself too large? Is one of the methods executed on the $discounts object causing the problem?

Try to set some breakpoints in your code to better find where the memory problem is being encountered.

I've found it can be tricky to get Symfony to free memory, though you might try setting $discounts = null; instead of unsetting it (see What's better at freeing memory with PHP: unset() or $var = null).

For simple bulk inserts like that I'd suggest doing the inserts with SQL (preferably PDO) instead of Doctrine.

You can destroy an object in PHP using unset(). That's what you are doing already.

In order to increase the memory available - you have to set the PHP config value

memory_limit

to a larger number.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top