Memory Management and Leak Visualizations

What are memory leaks?

No matter what programming language you code in the lifecycle of memory management is pretty much the same.

While this may seem pretty straightforward memory doesn’t always get released. In a simple app this is not a huge issue but in larger applications this can pile up and lead to the codebase experiencing a serious memory leak and the application may end up not working properly. While at the beginning you might just see slow performance, in the long term if unaddressed the leak can lead to bigger issues and crashes. In short, a memory leak is data that may not be garbage collected and is not put to use.

Chrome developer tools have a handy option for taking heap snapshots but the information is hard to decipher.

While we loved the v8 engine data we felt that there was a visual aspect that was missing. You could only view it from the Chrome dev tools memory tab. We used node-heapdump to get the information out of the browser and into our app. We also used WebSockets to send and receive data in real-time through a duplex stream between aether’s server and the client it’s installed on. WebSockets allow for a higher amount of efficiency compared to REST because they do not require the HTTP request/response overhead for each message sent and received.

The heap snapshot data that was coming back was initially overwhelming to look at and hard to make sense of. So in order to help us write better code and debug our codebases we parsed through the snapshots and developed a tool that would help us see at a glance the size of nodes and overall memory usage.

This chart shows the self size of the nodes in an application.

Self size — The size of the memory contained by the node itself. Very large objects will have large self sizes, like long strings, dictionaries, and functions with large bodies.

Retained size — The object’s self size plus the sizes of all of the objects that would be freed should the object be deleted.

This chart shows an example of spikes in memory usage in your application.

If you’re interested in trying it for yourself here is a link to the tool! https://github.com/oslabs-beta/aether/

我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章