Why is ActionController :: Metal Memory Leak?

I have the following class:


class Myclass < ActionController::Metal
  def myaction
    huge_object.do_something
    # etc.
  end

  private
  def huge_object
    @obj ||= begin
      # allocate and initialize a ~10MB object
    end
  end
end

What I was amazed at is that even in the production process, every time myaction is called, the object is allocated. Moreover, something holds a link to it, since the GC does not collect it. I made a workaround by wrapping the object in another class and including Singleton in this class. However, I want to understand what is happening here.

+3
source share
1 answer

This was mentioned in a rails comment about github issues that I think recently, you can find it there. In short, this is because the class variable is not touching between requests.

0
source

All Articles