About memory exhausted

I got a error message that shows,

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate xxx bytes) in Unknown on line 0

And tried to increase the memory limit in php int,

but the xxx bytes tried to allocate is more than the limit I can set.

The program is simple, just call model->find and use views to display, does not have any infinite loops.

I tried use memory_get_peak_usage(true) and memory_get_usage(true) in views before and after model->find,

but the memory shows by memory_get function is much less than the Fatal error shows.

Is there anything, memory function or extension I should try to figure out where or why exhausted memory?

Thank you.

Active records are quite expensive in terms of memory.

You should use them only if you have paging or some limit on the number, if you have a view in wich you can have some thounsands of records, better to use DAO

Thank you for reply,

I’ve found that if I import application.components.* and application.models.* in config file,

then I’ll got a fatal error which shows that memory exhausted.

But if I import each class in config file,

no error shows up.

Any advice for how to trace the cause this problem is appreciate.

Thank you for reading this.

That’s strange.

Are you sure that you have no strange circular reference in your components? Sometime can happen that a component render a component wich render the first one.

It sounds like some rougue code going on somewhere to cause that. Have you tried using xdebug to profile a request? It may help uncover clues as to where it is going bad.

I have import every class in components and models, and it’s fine now.

In components, I extends CGridView and CGridColumn, just override some function and echo html code.

In models, I have a class extends CActiveRecord, override getDbConnection for another database connection.

All other model in models is extends CActiveRecord or that class with tableName, rules…etc, just as normal model.

Does this cause circular reference?

It should not, anyway what happen to you is quite strange.

How many records are you managing at once?