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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access