0

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.

Community
  • 1
  • 1
JERC
  • 1,584
  • 3
  • 17
  • 38
  • Note that this is really a Doctrine (or Propel maybe?) issue rather than Symfony, I've added a tag. – John Carter Nov 27 '12 at 19:48
  • How many items do you have in `$array_data` ? By the way, you should try every update from this answer: http://stackoverflow.com/a/4066680/569101 – j0k Nov 27 '12 at 21:10
  • @j0k Thanks your answer will be my solution. – JERC Nov 27 '12 at 22:53

4 Answers4

1

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.

Community
  • 1
  • 1
John Carter
  • 53,924
  • 26
  • 111
  • 144
1

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.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
0

I have find the solution in these link:

php/symfony/doctrine memory leak?

Thanks for all your advices!

Community
  • 1
  • 1
JERC
  • 1,584
  • 3
  • 17
  • 38
-1

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.

madflow
  • 7,718
  • 3
  • 39
  • 54