Memory Size Error (or How I learned to overwrite ActiveRecord::init() instead of ActiveRecord::__construct())

In our application, I extended ActiveRecord with a class I gave the obvious name of ActiveRecordExtended, so I could attach a behavior to it and then have all my models extend from it, avoiding the need to attach the behavior to each of them.

In ActiveRecordExtended, I also added some protected member variables and assigned values to them in ActiveRecordExtended::__construct(), which called parent::__construct() as a final step in its method definition.

The first time I tried to run our app after making this change, I got the following error:


Allowed memory size of 16777216 bytes exhausted (tried to allocate 32 bytes) in /some/path/Public/yii-1.1.1.r1907/framework/db/ar/CActiveRecordBehavior 

I resolved the error by overwriting ActiveRecord::init() in ActiveRecordExtended, instead of redefining the parent __constructor() method.

I realize I can avoid the memory exhausted error by allocating more memory in php.ini, but I’d really like to understand what caused so much memory to be used.

Does anyone know? Or could anyone suggest where to start looking?

Thanks!

Tom

Try to use very helpful yii extension Yii Debug Toolbar and in your action try to retrieve from DB less records (like just 10 or even 1).