Read more

Ruby and Rails: Debugging a Memory Leak

Dominik Schöler
September 08, 2022Software engineer at makandra GmbH

A memory leak is an unintentional, uncontrolled, and unending increase in memory usage. No matter how small, eventually, a leak will cause your process to run out of memory and crash.

If you have learned about a memory leak, looking at the number of Ruby objects by type can help you track it down:

> pp ObjectSpace.count_objects
{:TOTAL=>77855,
 :FREE=>4526,
 :T_OBJECT=>373,
 :T_CLASS=>708,
 :T_MODULE=>44,
 :T_FLOAT=>4,
 :T_STRING=>65685,
 :T_REGEXP=>137,
 :T_ARRAY=>984,
 :T_HASH=>87,
 :T_STRUCT=>12,
 :T_BIGNUM=>2,
 :T_FILE=>3,
 :T_DATA=>203,
 :T_COMPLEX=>1,
 :T_SYMBOL=>29,
 :T_IMEMO=>5008,
 :T_ICLASS=>49}
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Look out for a number that keeps growing over time.

Rails

In a Rails application, you can use derailed_benchmarks Show archive.org snapshot to identify and examine memory leaks Show archive.org snapshot .

Resources

Posted by Dominik Schöler to makandra dev (2022-09-08 08:56)