Description
Add 300,000 users.
Turn on analytics.
Run php admin/cli/scheduled_task.php --execute=\\core\\task
analytics_cleanup_task
Notice memory error Fatal error.
Basically, each iteration of user does return \core_analytics\user::instance($record, $context), which does new \core_analytics\user($user, $context);
That allocates more memory.
The memory never gets freed in the loop in foreach ($analysables as $analysable) {
so there is a memory leak.
I think the easy fix to this would be to call unset($analysable) in \core_analytics\manager::cleanup()