• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Memory Leak In java
 

Memory Leak In java

on

  • 360 views

Talks about topics like What is Memory Leak, Symptoms of memory leak, Detecting memory leak & Preventing memory leak etc.

Talks about topics like What is Memory Leak, Symptoms of memory leak, Detecting memory leak & Preventing memory leak etc.

Statistics

Views

Total Views
360
Views on SlideShare
360
Embed Views
0

Actions

Likes
0
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Memory Leak In java Memory Leak In java Presentation Transcript

    • Memory Leaks in Java By Tanmayee Sahoo
    • Presentation Outline Introduction  Symptoms of memory leak  Detecting memory leak  Preventing memory leak  Question and Answer  1
    • Introduction In procedural language like C, before a developer uses a variable he/she has to manually allocate a region in the memory where the value will reside and once the application finishes using that value, the region of the memory must be manually freed by writing the code for this. But in java when a developer creates an object using the key word new JVM automatically allocates the memory for that object. 2
    • Introduction (cont…) During the life of the application JVM keeps on check which objects in memory are in use and which are not at a regular interval. Unused objects can be freed and memory occupied by the object can be reclaimed and reused. This process is called garbage collection and the corresponding piece of JVM is called garbage collector. Memory Leak in java is a situation when some of the objects are not used by the application 3
    • Introduction (cont…) any more but GC failed to recognize them as unused there by the unused objects remain in the memory indefinitely and the amount of memory available to the application is reduced. 4
    • Symptoms of memory leak When an application has memory leak we will notice the following things.  Memory usage consistently increases during the application life span. Sooner or later the application will crash because of out of memory.  Performance consistently decreases. 5
    • Detecting memory leak Several tools are available to detect memory leak in a java application such as:  Yourkit  Jprofiler  Visual VM  AppPerfect  JProbe 6
    • Preventing memory leak While writing code if we can take care of a few points we can avoid memory leak.  Avoid String Concatenation. Use StringBuilder.  Avoid unnecessary object creation. 7
    • Preventing memory leak (Cont…) Static Objects : By default live for the entire life of the application unless explicitly set to null. So it is better to set the references to null once the use the static member is over.  Avoid Using System.gc()  8
    • Preventing memory leak (Cont…)    9 Close ResultSet, Statement and Connection objects in finally block. Unregister Event listener class. Disable Jsp Page buffer if you are not using jsp feature that needs buffering so that performance will improve as memory will not be used in creating buffer and output will go directly to the browser.
    • Preventing memory leak (Cont…)  Set session = false in the jsp page if the page is not accessing the data from the session.  Avoid storing huge data in the session.  Invalidate the session when no longer used. Avoid duplicating libraries. For ex. If a library is shared among multiple modules in the same application then use WAR file manifest's CLASSPATH to share the libraries instead of  11
    • Preventing memory leak (Cont…) Duplicating the library in the WEB-INF/lib of each module.  12 Set session timeout appropriately.
    • Question and Answer ?? 13
    • Thank You 14