When I do lots of DB calls on a page it will die with a rather ambiguous "out of memory" error. I tracked it down to the debugger/profiler filling up.
I suggest to either:
Have a nice mode where the debugger/profiler stops (or deleting older ones) once it reaches a certain number of entries.
Give a better explanation of the memory usage.
Probably you are in infinite loop or are reading too much records.
Nope, turning off YII_DEBUG and everything works fine.
It can be that your script almost reach the memory limit and with debug option (which increase memory usage) it goes above.
Query can be memory eater. So if you have many query probably you are almost at the limit.
If possible try to release resources that you do not need any more in the execution.
Check also if you used Lazy or Eager Loading for your query
Lazy and Eager Loading