Posted 11 days ago. Visible to the public.

Rails: Fixing the memory leak in prepend_view_path

Recently we detected a memory leak in one of our applications. Hunting it down, we found that the memory leak was located in Rails' #prepend_view_path. It occurs when the instance method prepend_view_path is called in each request, which is a common thing in a multi-tenant application.

This is not a new memory leak. It was first reported in in 2014 Archive . Five years later, Frederick cheung wrote in detail how he chased down this memory leak Archive . Last year, mudge added some dev improvement Archive .

We took their solution a little further to prevent the leak at its root. With the attached module, you can just use #prepend_view_path as before.

Known affected Rails versions (maybe more): Rails 4.0 - 6.1

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Dominik Schöler
Last edit:
11 days ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more