SlideShare a Scribd company logo
1 of 14
Download to read offline
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

More Related Content

What's hot

What's hot (20)

Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
 
garbage collector
garbage collectorgarbage collector
garbage collector
 
Chap2 2 1
Chap2 2 1Chap2 2 1
Chap2 2 1
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Java basic introduction
Java basic introductionJava basic introduction
Java basic introduction
 
Java Performance Monitoring & Tuning
Java Performance Monitoring & TuningJava Performance Monitoring & Tuning
Java Performance Monitoring & Tuning
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Introduction to Eclipse IDE
Introduction to Eclipse IDEIntroduction to Eclipse IDE
Introduction to Eclipse IDE
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Java
JavaJava
Java
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecture
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Summer training presentation on "CORE JAVA".
Summer training presentation on "CORE JAVA".Summer training presentation on "CORE JAVA".
Summer training presentation on "CORE JAVA".
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 

Viewers also liked

Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇
bluedavy lin
 

Viewers also liked (20)

Be happy! Счастье - это просто выбор.
Be happy! Счастье - это просто выбор.Be happy! Счастье - это просто выбор.
Be happy! Счастье - это просто выбор.
 
Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇
 
Quality of Health Care
Quality of Health CareQuality of Health Care
Quality of Health Care
 
O femeie manager in cariera | www.mototol.ro |
O femeie manager in cariera | www.mototol.ro |O femeie manager in cariera | www.mototol.ro |
O femeie manager in cariera | www.mototol.ro |
 
Digital and customer experience: slides from CXFS - Antony Mayfield, Brillian...
Digital and customer experience: slides from CXFS - Antony Mayfield, Brillian...Digital and customer experience: slides from CXFS - Antony Mayfield, Brillian...
Digital and customer experience: slides from CXFS - Antony Mayfield, Brillian...
 
Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java code
 
Asynchronous PHP. Myth? Reality!
Asynchronous PHP. Myth? Reality!Asynchronous PHP. Myth? Reality!
Asynchronous PHP. Myth? Reality!
 
(MBL314) Build World-Class Cloud-Connected Products: Sonos
(MBL314) Build World-Class Cloud-Connected Products: Sonos(MBL314) Build World-Class Cloud-Connected Products: Sonos
(MBL314) Build World-Class Cloud-Connected Products: Sonos
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Administracion de Documentos Electronicos - Modelo de Gestión Documental MGD-RTA
Administracion de Documentos Electronicos - Modelo de Gestión Documental MGD-RTAAdministracion de Documentos Electronicos - Modelo de Gestión Documental MGD-RTA
Administracion de Documentos Electronicos - Modelo de Gestión Documental MGD-RTA
 
Kettle Chips revamp
Kettle Chips revamp Kettle Chips revamp
Kettle Chips revamp
 
Utz integrated mktg presentation
Utz integrated mktg presentationUtz integrated mktg presentation
Utz integrated mktg presentation
 
Duterte cabinet secretary
Duterte cabinet secretaryDuterte cabinet secretary
Duterte cabinet secretary
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission Control
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Brands in the digital age - Google Squared
Brands in the digital age - Google SquaredBrands in the digital age - Google Squared
Brands in the digital age - Google Squared
 
The Art of Social Media in Asia Pacific with Guy Kawasaki
The Art of Social Media in Asia Pacific with Guy KawasakiThe Art of Social Media in Asia Pacific with Guy Kawasaki
The Art of Social Media in Asia Pacific with Guy Kawasaki
 
River profile
River profileRiver profile
River profile
 
PSFK Technology Debrief: Virtual Reality
PSFK Technology Debrief: Virtual RealityPSFK Technology Debrief: Virtual Reality
PSFK Technology Debrief: Virtual Reality
 
Comic-Con 2016 - Beyond Human: The Rise Of Machine Intelligence #SDCC
Comic-Con 2016 - Beyond Human:  The Rise Of Machine Intelligence #SDCCComic-Con 2016 - Beyond Human:  The Rise Of Machine Intelligence #SDCC
Comic-Con 2016 - Beyond Human: The Rise Of Machine Intelligence #SDCC
 

Similar to Memory Leak In java

MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
Narinder Kumar
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
sidg75
 

Similar to Memory Leak In java (20)

performance optimization: Memory
performance optimization: Memoryperformance optimization: Memory
performance optimization: Memory
 
Detecting Memory Leaks in Android App
Detecting Memory Leaks in Android AppDetecting Memory Leaks in Android App
Detecting Memory Leaks in Android App
 
ACADGILD:: ANDROID LESSON-How to analyze & manage memory on android like ...
ACADGILD:: ANDROID LESSON-How to analyze & manage memory on android like ...ACADGILD:: ANDROID LESSON-How to analyze & manage memory on android like ...
ACADGILD:: ANDROID LESSON-How to analyze & manage memory on android like ...
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applications
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applications
 
Memory Leaks in Android Applications
Memory Leaks in Android ApplicationsMemory Leaks in Android Applications
Memory Leaks in Android Applications
 
Android Memory Management
Android Memory ManagementAndroid Memory Management
Android Memory Management
 
Memory Heap Analysis with AppDynamics - AppSphere16
Memory Heap Analysis with AppDynamics - AppSphere16Memory Heap Analysis with AppDynamics - AppSphere16
Memory Heap Analysis with AppDynamics - AppSphere16
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
 
Postmortem of a uwp xaml application development
Postmortem of a uwp xaml application developmentPostmortem of a uwp xaml application development
Postmortem of a uwp xaml application development
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
 
Short notes of oop with java
Short notes of oop with javaShort notes of oop with java
Short notes of oop with java
 
Javasession10
Javasession10Javasession10
Javasession10
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012
 
CAR SHOWROOM SYSTEM
CAR SHOWROOM SYSTEMCAR SHOWROOM SYSTEM
CAR SHOWROOM SYSTEM
 
Library Managemnet System
Library Managemnet SystemLibrary Managemnet System
Library Managemnet System
 

More from Mindfire Solutions

More from Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Memory Leak In java

  • 1. Memory Leaks in Java By Tanmayee Sahoo
  • 2. Presentation Outline Introduction  Symptoms of memory leak  Detecting memory leak  Preventing memory leak  Question and Answer  1
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. Detecting memory leak Several tools are available to detect memory leak in a java application such as:  Yourkit  Jprofiler  Visual VM  AppPerfect  JProbe 6
  • 8. 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
  • 9. 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
  • 10. 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.
  • 11. 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
  • 12. Preventing memory leak (Cont…) Duplicating the library in the WEB-INF/lib of each module.  12 Set session timeout appropriately.