CActiveFinder memory leaks




// YII_DEBUG => false

// No one of ARModel didn't has behaviors

// PHP version is 5.2.13 (apache/2.2.14 win xp sp3)




$db = Yii::app()->getDb();

$i=20;

echo "<pre>";


while($i--){

	echo memory_get_usage(true)."\n";


	// flush connection to prevent PDO leaks

	$db->setActive(false);

	$db->setActive(true);


	SomeArRecord::model()->findAll(array(

		'with'=>array(

			'related' => array(

				'with' => array(

					'related',

					'related2',

				),

			),

			'related2',

		),

		'limit'=>1000,

	));

}

output:




2359296

9699328

12845056

16252928

19398656

22544384

25952256

29097984

32243712

35389440

38535168

42467328

45613056

48758784

51904512

55050240

58195968

61341696



Any suggestions?

  • one more interesting thing: if add few lines to CActiveFinder/CActiveRecord/CJoinElement

public function __destruct(){

  echo "destructed\n";

}

__destruct’s output will appears after all “memory lines” :huh: (I mean that AR need to be refactored, because all of result instances (with related object) live until script shutdown) - need use temporary cache instead of object’s properties

Hello !

I recently ran into the exact same problem, and opened a topic in the bug forum :

http://www.yiiframework.com/forum/index.php?/topic/9624-memory-leak-with-relational-active-record-and-php53/page__view__findpost__p__47449

In this post, I proposed a little hack that solved the problem for me.

You may want to give it a try ;)