-
Bug
-
Resolution: Fixed
-
Critical
-
3.0.6, 3.1.2, 3.2
-
MOODLE_30_STABLE, MOODLE_31_STABLE, MOODLE_32_STABLE
-
MOODLE_30_STABLE, MOODLE_31_STABLE
-
MDL-56748-master -
While testing MDL-48468, it was observed that there was some memory leak.
After debugging dobedobedoh found that the cache store instances were not been cleaned while purging cache.
Comments from MDL-48468:
Essentially it boils down to the fact that the our unit testing framework purges the cache, and it also removes the cache definitions, but it does not actually remove the cache store instances for those definitions.
Every time a cache is created (e.g. via cache::make), an instance of a cache_store is created and stored (technically it's cloned, but that's not the point).
The newly created cache_store instance is then stored in an anonymous array at cache_factory::$definitionstores.
This is only used to facilitate fetching of all definition stores via get_store_instances_in_use. Items are never fetched out of the array again and there are no uses of this function in core.
Between unit tests we purge all caches (cache_helper::purge_all()) and we then reset the cache (cache_factory::reset().
The cache_helper::purge_all() function purges the caches, but does nothing more.
The cache_factory::reset() function empties all of the base cache_store instances, the definitions, the config, the actual caches from definitions, but it does not remove the definition stores.
As a result, on the next test after a purge, we create a new store, and a new definition store, based on the definition. Since we cannot actually fetch the store from cache_factory::$definitionstores, we append the new store to the array.
As a result cache_factory::$definitionstores grows in size every time a test requires resetAfterTest and the number of items in the array hit a total of 23,511 in my testing.
From my local testing of my solution to this issue, phpunit memory consumption on php7 drops by 70MB.
- Discovered while testing
-
MDL-48468 Add a Redis cache store to Moodle core
- Closed