A pragmatic and simple approach to fixing a memory leak

July 14, 2023 28 min Free

Description

Memory leaks are rare in modern Rails applications, but when they occur, finding and fixing them can be a complex and time-consuming process, often requiring deep knowledge of Ruby's memory management and specialized profiling tools. In this talk, Vincent Rolea shares a real-world experience of encountering and resolving a memory leak in a background worker. He walks through the challenges, the initial unsuccessful attempts at scaling and refactoring, and the eventual pragmatic solution using a binary search-like approach to isolate the problematic job. The talk emphasizes taking a step back to find simpler solutions to complex problems and highlights how a methodical approach, even without extensive tooling, can lead to effective resolution. The discussion also delves into the underlying cause of the leak, related to how Ruby blocks retain context and object references, and how to prevent such issues in the future by optimizing the instantiation of libraries.