Render cache memory usage grows continuously during sustained page rendering
0 reputation · 20 Jul 2021, 16:07 UTC
0 reputation · 20 Jul 2021, 16:07 UTC
Under sustained page rendering, Drupal's render cache consumes increasing memory, eventually exhausting the PHP memory limit.
Determine whether to enable automatic garbage collection of orphaned cache tags in the database cache backend to keep the cache_tags table bounded after the render cache memory leak fix.
The fix prevents new leaks but does not automatically remove existing orphaned tags; administrators must decide on a cleanup schedule or enable automatic GC, weighing potential performance overhead against storage growth.
34775 reputation · 21 Jul 2021, 00:20 UTC
Yes — enable automatic garbage collection of orphaned cache tags on sites using the database cache backend, but understand that it will not fix your PHP memory exhaustion. These are two separate problems: the memory growth is a process-level leak (addressed by the render cache fix you mentioned), while cache_tags GC is a storage-hygiene measure that keeps the table bounded. Apply the leak fix first, verify memory is stable, then turn on tag cleanup via cron.
Continuously growing PHP memory during sustained rendering almost always comes from accumulating render array metadata, static caches, or repeated entity loads inside a long-running process (drush, queue workers, test runners). The cache_tags table lives in the database — it consumes disk, not PHP memory. A bloated cache_tags table can slow tag invalidation lookups, but it cannot exhaust the PHP memory limit by itself.
Confirmed behavior: the database cache backend records tag invalidations in cache_tags, and rows belonging to deleted cache items are not removed automatically by default, so the table grows unboundedly on write-heavy sites. Drupal core provides an opt-in tag garbage collection mechanism that purges orphaned/invalidated tag records during cron rather than on every request.
For your site: yes, enable it. The cost is a periodic DELETE against cache_tags during cron, which is far cheaper than the alternative — an ever-growing table that degrades invalidation performance and complicates backups. Running cleanup on every request would add DELETE queries under load; keep it on cron only.
memory_get_usage() (or a profiler) across a sustained render loop before and after applying the render cache fix. Memory should plateau, not climb linearly.drush sqlq "SELECT COUNT(*) FROM cache_tags;"
drush cron
drush sqlq "SELECT COUNT(*) FROM cache_tags;"
The count should drop after cron if orphaned rows existed.
Exact GC configuration names and availability vary by Drupal core minor version — confirm against your installed version's documentation before relying on a specific setting key. If memory still grows after the fix, the remaining suspect is custom code holding references in a long-running process, not the cache backend.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.