CActiveRecordBehavior as a Singleton?

I’ve got a page that loads approx 2,000 active record objects. (Which I realize is a lot, but I’m doing most of this in a couple of queries, not one at a time.) I’m running into some problems with memory on my production server and am looking for fat to trim. Because the out of memory error happened in one of the behaviors that I’ve attached to my entities I have been looking into the behavior implementation. It looks like for every active record it creates a separate instance of every behavior. So if I’ve got 2,000 AR on a page and 2 behaviors for every AR then I’ve got 6,000 objects from this alone…

The behaviors that I’ve implemented could be singletons, is there an easy way to force Yii to not create a new one for every AR?

Solved this one myself, but for anyone else who is curious you can do this:

private static $_behaviors;

public function behaviors()




		self::$_behaviors = array(

			'behavior1' => new Behavior1(),

			'behavior2' => new Behavior2()



	return self::$_behaviors;


Interesting. What behaviors have you used?