Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Plumbing Memory Leaks

Plumbing Memory Leaks

Avatar for Nikita Salnikov-Tarnovski

Nikita Salnikov-Tarnovski

April 17, 2014
Tweet

More Decks by Nikita Salnikov-Tarnovski

Other Decks in Programming

Transcript

  1. Who am I • Nikita Salnikov-Tarnovski! • Founder and Master

    Developer from ! • We solve performance problems! • @iNikem, @JavaPlumbr
  2. JVM and memory • When JVM runs, it uses different

    regions of memory! • Native! • Heap (Young generation and Old generation)! • Permanent Generation
  3. Java memory management • JVM has automatic memory management! •

    Developers don’t think about it! • They just new and go on
  4. Garbage Collector • Subsystem of JVM for reclaiming “unused” memory!

    • Memory occupied by unused objects! • Not JVM specific, many runtimes have it! • Different algorithms
  5. GC “wizardry” • GC is not mind reading magician! •

    It always works by very specific and strict algorithm! • “No references, thus garbage”
  6. Reachability • Mark all GC roots as “reachable”! • Mark

    all objects referenced from “reachable” objects as “reachable” too! • Repeat until all reachable objects found! • Everything else is garbage and can be thrown away
  7. Memory leak • Reachable object(s), that will never be used

    by application! • Repetitive creation of such objects
  8. Examples • Caches without look-ups and eviction! • String.substring! •

    Immortal threads! • Unclosed IO streams! • Storages with longer lifespan than stored values
  9. Not a memory leak • Too high allocation rate! •

    Cache with wrong size! • Trying to load too much data at once! • Fat data structures
  10. GC pauses • GC has to stop the world to

    do his job! • These pauses are almost unpredictable! • Huge impact on users’ perception
  11. GC overhead • GC shares CPU with your application! •

    Whenever he wants CPU, he just takes it
  12. Results • crashes, sometimes together with the application;! • tons

    of flickering dashboards, graphics, buttons, bells and whistles, but no answer;! • console full of cryptic text and java class names;! • … or application adapted for snails and turtles, with response times increased 5-350 times.! • http://plumbr.eu/blog/solving-outofmemoryerror-no- tools-will-help-you
  13. Memory Analyzer (MAT) • From Eclipse! • It really works

    for finding memory leaks! • If you have experience! • http://www.eclipse.org/mat/
  14. Plumbr • Java agent monitoring your application! • In case

    of problem reports you exact details! • Memory leak, class loader leaks! • GC related problems soon