Memory leak - WHERE???!!!!

Here is the code, that gives memory leaks when deals with file with long lines (less than 1Kb):

protected function insertFile($file, $table, $offset)


	$fl = fopen(self::IMPORT_DIR.$file,'r');

	$headings = fgetcsv($fl, 1024, "\t");

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

	$sqlPart = 'INSERT INTO `'.$table.'` (`'.implode('`,`', $headings).'`) VALUES(\'';

	$suc = 0;

	$err = 0;

	$i = 0;

	while ($i < $offset)





	$i = 0;

	while (!feof($fl) && $i < self::LINES_PER_PROCESS)


		$row = fgetcsv($fl, 1024, "\t");

		$sql = $sqlPart.implode('\',\'', $row).'\')';




			$cmd = $db->createCommand($sql);

			$res = $cmd->execute();





		catch (CException $e)


			echo $sql."\n";









	echo $suc." lines inserted; $err errors encountered\n";


Why does it give errors??? Where is memory leaks? I unset all variables I create, how this code can leak?

I guess it’s because you set YII_DEBUG to be true and thus the logging messages (in CDbCommand) are accumulated as you execute many SQLs. You can set YII_DEBUG to be false.

P.S no need to unset every single variable you set.

I know there is no need for this, I was trying to find the way to make it work :)

thanks Qiang, will try it now.

I found out that it already had YIIDEBUG commented out. I also commented out logging in the config file.

But the problem persists. What else can be done here?

I also found out that memory is usually our on the various lines of YiiBase file where public static function t is defined.

It is very strange cause I don’t use i18n in the app, how can this method be called at all?

Can you describe what you mean by "memory leak"? How much memory is consumed? Is the consumption piled up?


I have the same problem

any solution?