CRM-20754 - Clear memory leak in CSV CLI import
authorJon goldberg <jon@palantetech.coop>
Wed, 21 Jun 2017 14:07:31 +0000 (10:07 -0400)
committerJon goldberg <jon@palantetech.coop>
Wed, 21 Jun 2017 14:07:31 +0000 (10:07 -0400)
bin/cli.class.php

index dbcc5e9caf01268e28dc77b6e38b980b31863dbb..f450b74b51d093253e2ba7409fa823e216c9f4d5 100644 (file)
@@ -430,6 +430,14 @@ class civicrm_cli_csv_file extends civicrm_cli {
         continue;
       }
       $this->row++;
+      if ($this->row % 1000 == 0) {
+        // Reset PEAR_DB_DATAOBJECT cache to prevent memory leak
+        $GLOBALS['_DB_DATAOBJECT']['RESULTS'] = array();
+        $GLOBALS['_DB_DATAOBJECT']['RESULTSEQ'] = 1;
+        $GLOBALS['_DB_DATAOBJECT']['RESULTFIELDS'] = array();
+        // Forces garbage collection
+        memory_get_usage(true);
+      }
       $params = $this->convertLine($data);
       $this->processLine($params);
     }