From 6c07d162053e541fd8149b222898979652c341a5 Mon Sep 17 00:00:00 2001 From: Jon goldberg Date: Wed, 21 Jun 2017 10:07:31 -0400 Subject: [PATCH 1/3] CRM-20754 - Clear memory leak in CSV CLI import --- bin/cli.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/cli.class.php b/bin/cli.class.php index dbcc5e9caf01..f450b74b51d0 100644 --- a/bin/cli.class.php +++ b/bin/cli.class.php @@ -430,6 +430,14 @@ public function run() { 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); } From 0d379049e1a0d821e6e274314e05a98ed7e8f1a6 Mon Sep 17 00:00:00 2001 From: Jon goldberg Date: Wed, 21 Jun 2017 21:31:49 -0400 Subject: [PATCH 2/3] style fix --- bin/cli.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.class.php b/bin/cli.class.php index f450b74b51d0..d38259182464 100644 --- a/bin/cli.class.php +++ b/bin/cli.class.php @@ -436,7 +436,7 @@ public function run() { $GLOBALS['_DB_DATAOBJECT']['RESULTSEQ'] = 1; $GLOBALS['_DB_DATAOBJECT']['RESULTFIELDS'] = array(); // Forces garbage collection - memory_get_usage(true); + memory_get_usage(TRUE); } $params = $this->convertLine($data); $this->processLine($params); From 39a545dcdb48f06c4c32fe3f85478aa0ebfd7fd1 Mon Sep 17 00:00:00 2001 From: Jon goldberg Date: Mon, 17 Jul 2017 00:50:42 -0400 Subject: [PATCH 3/3] Use the freeResult DAO method --- bin/cli.class.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/cli.class.php b/bin/cli.class.php index d38259182464..5020e8171ba4 100644 --- a/bin/cli.class.php +++ b/bin/cli.class.php @@ -432,11 +432,7 @@ public function run() { $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); + CRM_Core_DAO::freeResult(); } $params = $this->convertLine($data); $this->processLine($params);