# Tracking down a memory leak in Ruby's EventMachine

DevFeed: [Tracking down a memory leak in Ruby's EventMachine](<https://devfeed.tech/articles/tracking-down-a-memory-leak-in-ruby-s-eventmachine-21932.md>)

Original publisher: [Read original article](<https://blog.nelhage.com/2013/03/tracking-an-eventmachine-leak/>)

Author: Nelson Elhage

Published: 2013-03-07T13:13:37Z

Content type: tutorial

Language: en

Sources: [Nelson Elhage](<https://devfeed.tech/sources/nelson-elhage.md>)

Topics: [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [Post Mortem](<https://devfeed.tech/topics/post-mortem.md>), [Monitoring](<https://devfeed.tech/topics/monitoring.md>), [stripe](<https://devfeed.tech/topics/stripe.md>)

Tags: [debugging](<https://devfeed.tech/tags/debugging.md>), [gdb](<https://devfeed.tech/tags/gdb.md>), [leak](<https://devfeed.tech/tags/leak.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [monitoring](<https://devfeed.tech/tags/monitoring.md>), [post-mortem](<https://devfeed.tech/tags/post-mortem.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [techniques](<https://devfeed.tech/tags/techniques.md>), [tools](<https://devfeed.tech/tags/tools.md>)

## AI overview

This article describes how Stripe investigated a gradual memory leak in a Ruby service using EventMachine. It covers monitoring and process restarts as a workaround, then explores post-mortem analysis, gdb, the Ruby C API, garbage-collection hooks, and Ruby ObjectSpace to determine whether Ruby-level objects explained the service's multi-gigabyte memory use.

## Source excerpt

At Stripe, we rely heavily on ruby and EventMachine to power various internal and external services. Over the last several months, we've known that one such service suffered from a gradual memory leak, that would cause its memory usage to gradually balloon from a normal ~50MB to multiple gigabytes. It was easy enough to work around the leak by adding monitoring and restarting the process whenever memory usage grew too large, but we were determined to track down the root cause.