Ticker

6/recent/ticker-posts

cakePHP : memory leak issue - some times an evil

When you work on cake's model, some time it says like:


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 76 bytes) in/var/www/html/demoer/cake/libs/model/datasources/dbo/dbo_mysql.php on line 751


To avoid these issues we should:

1. Use recursive clause in conditions, 

$this->find('all', array('conditions' => array("is_enabled" => '1'), 'order' => array('Post.name ASC'), 'recursive' => -1));
 if you don't do this, cake will automatically gather all the subsequent dependencies realted to your model.

For example, if a Post has 123456756 comments, and you want that post to be displayed, and if you did not use recursive clause, then it'll load all comment to object returned by above statement, that will result the memory leak.

Post a Comment

0 Comments