diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 46509d248949..e262cff88aeb 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -1000,10 +1000,6 @@ public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALS CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact); } - // also reset the DB_DO global array so we can reuse the memory - // http://issues.civicrm.org/jira/browse/CRM-4387 - CRM_Core_DAO::freeResult(); - return TRUE; } diff --git a/CRM/Contact/Import/Parser.php b/CRM/Contact/Import/Parser.php index 6085e8a5a038..dbb465905dfe 100644 --- a/CRM/Contact/Import/Parser.php +++ b/CRM/Contact/Import/Parser.php @@ -275,9 +275,6 @@ public function run( break; } - // clean up memory from dao's - CRM_Core_DAO::freeResult(); - // see if we've hit our timeout yet /* if ( $the_thing_with_the_stuff ) { do_something( ); diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index a41d9367a73f..04c4b273bd68 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -660,7 +660,6 @@ static public function triggerUpdate($event) { } $updateDAO = CRM_Core_DAO::cascadeUpdate($daoName, $obj->id, $entityID, $skipData); - CRM_Core_DAO::freeResult(); } else { CRM_Core_Error::fatal("DAO Mapper missing for $entityTable."); diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 5ab5d76d529e..6a3ee88bdbd7 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -119,6 +119,13 @@ public function __construct() { $this->__table = $this->getTableName(); } + /** + * Class destructor. + */ + public function __destruct() { + $this->free(); + } + /** * Empty definition for virtual function. */ diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 12c3903d8c28..4acc24eb5d40 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1404,7 +1404,6 @@ public static function getRowsElementsAndInfo($mainId, $otherId, $checkPermissio $otherTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], NULL, $otherId, -1, CRM_Utils_Array::value('contact_sub_type', $other), NULL, TRUE, NULL, TRUE, $checkPermissions ); - CRM_Core_DAO::freeResult(); foreach ($otherTree as $gid => $group) { $foundField = FALSE; @@ -2256,8 +2255,6 @@ protected static function dedupePair(&$migrationInfo, &$resultStats, &$deletedCo // pair may have been flipped, so make sure we delete using both orders CRM_Core_BAO_PrevNextCache::deletePair($mainId, $otherId, $cacheKeyString, TRUE); } - - CRM_Core_DAO::freeResult(); } } diff --git a/tests/phpunit/api/v3/EntityTagTest.php b/tests/phpunit/api/v3/EntityTagTest.php index 714c910d56e0..c788802ad083 100644 --- a/tests/phpunit/api/v3/EntityTagTest.php +++ b/tests/phpunit/api/v3/EntityTagTest.php @@ -139,6 +139,19 @@ public function testIndividualEntityTagGet() { $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__, __FILE__); } + /** + * Test memory usage does not escalate crazily. + */ + public function testMemoryLeak() { + $start = memory_get_usage(); + for ($i = 0; $i < 100; $i++) { + $this->callAPISuccess('EntityTag', 'get', []); + $memUsage = memory_get_usage(); + } + $max = $start + 2000000; + $this->assertTrue($memUsage < $max, "mem usage ( $memUsage ) should be less than $max (start was $start) "); + } + /** * Test tag can be added to a household. */