Memory Profiling
What is Memory Profiling
Analyzing a program's behavior to determine
its memory usage.
Why Memory Profiling?
• Better understanding of your application and architecture
• Reduced hardware
• Maintenance costs
• Learn how to write better code
What is Memory Leak?
A memory leak is any condition in which the program
continues to hold memory allocated after the data it holds it
is no longer needed
Memory Leak
Demo using VisualVM
Few scenarios for memory leak
• Managing a List instance where you are only adding to the list and not
deleting from it
• Opening Sockets or Files, but not closing them when they are no
longer needed
• Opening Files, but not closing them when they are no longer needed
• Not unloading Singletons when bringing down a Java EE application.
• Few others….
Tools – Memory Profiling
• dotMemory – JetBrains
• YourKit Java Profiler
• VisualVM
• Chrome – Developer tools
• .Net Memory Profiler – Red Gate
Thank You !!

Memory Profiling

  • 1.
  • 2.
    What is MemoryProfiling Analyzing a program's behavior to determine its memory usage.
  • 3.
    Why Memory Profiling? •Better understanding of your application and architecture • Reduced hardware • Maintenance costs • Learn how to write better code
  • 4.
    What is MemoryLeak? A memory leak is any condition in which the program continues to hold memory allocated after the data it holds it is no longer needed
  • 5.
  • 7.
  • 8.
    Few scenarios formemory leak • Managing a List instance where you are only adding to the list and not deleting from it • Opening Sockets or Files, but not closing them when they are no longer needed • Opening Files, but not closing them when they are no longer needed • Not unloading Singletons when bringing down a Java EE application. • Few others….
  • 9.
    Tools – MemoryProfiling • dotMemory – JetBrains • YourKit Java Profiler • VisualVM • Chrome – Developer tools • .Net Memory Profiler – Red Gate
  • 10.

Editor's Notes

  • #5 sds
  • #6 Unlike C/C++, Java has a garbage that eventually frees all unreferenced instances. This means that there are no classic memory leaks in Java where you forget to delete an object or a memory region. However, in Java you can forget something else: to remove all references to an instance so that the object can be garbage collected. If an object is only ever held in a single location, this may seem simple, but in many complex systems objects are passed around through many layers, each of which can add a permanent reference to the object. collector
  • #9 Apparently, the Classloader that loaded the singleton class will retain a reference to the class, and hence the singleton instance will never be collected. When a new instance of the application is deployed, a new class loader is usually created, and the former class loader will continue to exist due to the singleton.