Memory leak in CDbCommand->execute()


I am using oci8pdo extension for Oracle DB and running following code.

    private function runInsertCommand($inserts, $params, $connection, $log = false)


        //Here we will insert the records to table.

        $query = $this->structureQuery($inserts);

        $command = $connection->createCommand($query);


        // for checking memory usage

        echo memory_get_usage();


        echo memory_get_usage();


The query insert 100 records. Each time $command->execute() is called, roughly 2MB increased. With 200 records, the memory spike to 4MB (each time), 2,000 records, the memory usage is 40MB and so on! I already tried setting YII_DEBUG = false, unsetting all the variables and still to no avail. Can anyone help/guide me to resolve this issue?



What PHP version are you using? This looks more like a garbage collection problem in PHP versions below 5.3.

I am using PHP 5.3.3 version and YII 1.1.3. I also tried calling garbage collector in the function but to no avail. This issue has been in the system for quite long time and we are able to track it to this point. I also check the execute function code and seems reasonable to me.

Confirming that the CDbCommand have memory leak in it! Surprised nobody reported it yet. Alternative solution is to use oci function directly from your DAL layer. For example, i have used following code to insert the data into oracle DB. Checked with 1 million records, no memory leak!

$conn = oci_pconnect($username, $password, $database);

$this->conn = $conn;

$parsed = @oci_parse($this->conn, $sql);

$this->stmt = $parsed;

$clob = array();

//bind parameters

foreach($this->params as $key=>$value){

    $clob[$key] = oci_new_descriptor($this->conn, OCI_D_LOB);


         self::logData("ERROR BINDING PARAMS");





Maybe because there is no memory leak. The way you describe it it might just be overhead from PDO. But when you strongly suspect you did find a bug you should discuss it in the Bug discussion forum.