Creating a Memory Leak

If you don’t have any bugs, you don’t need any management or profiling tools. To make this chapter feel more like real life, you’ll need to introduce a problem into Twitalytics so you can simulate the actual process of detecting, tracing, and resolving a real-life memory leak.

Open Twitalytics’s app/controllers/post_controller.rb file and add this code to the index method:

 @@leaky ||= []
 @@leaky << (1..1000).map{ rand(1 << 256) }

This creates a class variable, which is held in memory until the process is stopped. Then it adds one thousand random Bignum instances to the array. The Bignum class isn’t used very often, so it will be easy to identify with the tools you’ll learn about. Now when you want to simulate a problem, ...

Get Deploying with JRuby 9k now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.