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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)