SlideShare a Scribd company logo
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 (20)

PPT
Cursors
Raghav Chhabra
 
PDF
Feature Driven Development
Christophe Marchal
 
PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Haribabu Nandyal Padmanaban
 
PDF
Java Profiling Future
Jaroslav Bachorik
 
PPTX
Applications of SOA and Web Services in Grid Computing
yht4ever
 
DOC
ANDROID LAB MANUAL.doc
Palakjaiswal43
 
KEY
JavaScript: Operators and Expressions
LearnNowOnline
 
PPTX
waterfall model
Shiva Krishna
 
PPTX
Object detection presentation
AshwinBicholiya
 
PDF
Agile Methods - course notes
Evan Leybourn
 
PDF
Jira as a Project Management Tool
Paolo Mottadelli
 
PDF
Chapter 6 software metrics
despicable me
 
PDF
Software Development Life Cycle (SDLC)
Angelin R
 
PPTX
Waterfall model
BHARGAV VISANI
 
PPTX
Introduction to Software Engineering
SADEED AMEEN
 
PPTX
Waterfall model in SDLC
HND Assignment Help
 
PDF
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!
 
PDF
Basic Java Programming
Math-Circle
 
PDF
PMI-ACP Lesson 9 Agile Risk Management
Thanh Nguyen
 
PPTX
Java spring ppt
natashasweety7
 
Feature Driven Development
Christophe Marchal
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Haribabu Nandyal Padmanaban
 
Java Profiling Future
Jaroslav Bachorik
 
Applications of SOA and Web Services in Grid Computing
yht4ever
 
ANDROID LAB MANUAL.doc
Palakjaiswal43
 
JavaScript: Operators and Expressions
LearnNowOnline
 
waterfall model
Shiva Krishna
 
Object detection presentation
AshwinBicholiya
 
Agile Methods - course notes
Evan Leybourn
 
Jira as a Project Management Tool
Paolo Mottadelli
 
Chapter 6 software metrics
despicable me
 
Software Development Life Cycle (SDLC)
Angelin R
 
Waterfall model
BHARGAV VISANI
 
Introduction to Software Engineering
SADEED AMEEN
 
Waterfall model in SDLC
HND Assignment Help
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!
 
Basic Java Programming
Math-Circle
 
PMI-ACP Lesson 9 Agile Risk Management
Thanh Nguyen
 
Java spring ppt
natashasweety7
 

Viewers also liked (20)

PPTX
Be happy! Счастье - это просто выбор.
Alena Simonova
 
PPTX
Sun jdk 1.6内存管理 -使用篇
bluedavy lin
 
PPT
Quality of Health Care
Sveikatos Ekonomikos Centras
 
DOC
O femeie manager in cariera | www.mototol.ro |
Mototol Romania
 
PDF
Digital and customer experience: slides from CXFS - Antony Mayfield, Brillian...
Antony Mayfield
 
PDF
Performance optimization techniques for Java code
Attila Balazs
 
PPT
Asynchronous PHP. Myth? Reality!
Alexander Lisachenko
 
PPT
Java Performance Tuning
Minh Hoang
 
PPTX
Administracion de Documentos Electronicos - Modelo de Gestión Documental MGD-RTA
Hiriam Eduardo Perez Vidal
 
PPTX
Kettle Chips revamp
nwright2016
 
PDF
Utz integrated mktg presentation
Dejan Djordjevic
 
PPT
Duterte cabinet secretary
Arvin Dela Cruz
 
PDF
Introduction of Java GC Tuning and Java Java Mission Control
Leon Chen
 
PPT
Jvm Performance Tunning
Terry Cho
 
PDF
Brands in the digital age - Google Squared
Antony Mayfield
 
PDF
The Art of Social Media in Asia Pacific with Guy Kawasaki
HubSpot
 
PPTX
River profile
Steven Heath
 
PDF
PSFK Technology Debrief: Virtual Reality
PSFK
 
PPTX
Comic-Con 2016 - Beyond Human: The Rise Of Machine Intelligence #SDCC
Danny Sullivan
 
PDF
How To Sell On Amazon Successfully
Bobsled Marketing
 
Be happy! Счастье - это просто выбор.
Alena Simonova
 
Sun jdk 1.6内存管理 -使用篇
bluedavy lin
 
Quality of Health Care
Sveikatos Ekonomikos Centras
 
O femeie manager in cariera | www.mototol.ro |
Mototol Romania
 
Digital and customer experience: slides from CXFS - Antony Mayfield, Brillian...
Antony Mayfield
 
Performance optimization techniques for Java code
Attila Balazs
 
Asynchronous PHP. Myth? Reality!
Alexander Lisachenko
 
Java Performance Tuning
Minh Hoang
 
Administracion de Documentos Electronicos - Modelo de Gestión Documental MGD-RTA
Hiriam Eduardo Perez Vidal
 
Kettle Chips revamp
nwright2016
 
Utz integrated mktg presentation
Dejan Djordjevic
 
Duterte cabinet secretary
Arvin Dela Cruz
 
Introduction of Java GC Tuning and Java Java Mission Control
Leon Chen
 
Jvm Performance Tunning
Terry Cho
 
Brands in the digital age - Google Squared
Antony Mayfield
 
The Art of Social Media in Asia Pacific with Guy Kawasaki
HubSpot
 
River profile
Steven Heath
 
PSFK Technology Debrief: Virtual Reality
PSFK
 
Comic-Con 2016 - Beyond Human: The Rise Of Machine Intelligence #SDCC
Danny Sullivan
 
How To Sell On Amazon Successfully
Bobsled Marketing
 
Ad

Similar to Memory Leak In java (20)

PDF
performance optimization: Memory
晓东 杜
 
PPTX
Detecting Memory Leaks in Android App
Dinesh Prajapati
 
ODT
ACADGILD:: ANDROID LESSON-How to analyze & manage memory on android like ...
Padma shree. T
 
PPT
Efficient Memory and Thread Management in Highly Parallel Java Applications
pkoza
 
PPTX
Profiling JavaScript Performance
Noam Kfir
 
PPT
Efficient Memory and Thread Management in Highly Parallel Java Applications
Phillip Koza
 
PDF
Memory Leaks in Android Applications
Lokesh Ponnada
 
PPTX
Android Memory Management
Sadmankabirsoumik
 
PDF
Memory Heap Analysis with AppDynamics - AppSphere16
AppDynamics
 
DOC
MC0078 SMU 2013 Fall session
Narinder Kumar
 
PPTX
Postmortem of a uwp xaml application development
David Catuhe
 
PDF
JAVA INTRODUCTION
Prof Ansari
 
PDF
JAVA INTRODUCTION
Prof Ansari
 
PPSX
Short notes of oop with java
Mohamed Fathy
 
PPTX
Javasession10
Rajeev Kumar
 
PDF
Java Developer Roadmap PDF By ScholarHat
Scholarhat
 
DOC
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
sidg75
 
PDF
20 most important java programming interview questions
Gradeup
 
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Ashish Bhasin
 
DOCX
CAR SHOWROOM SYSTEM
Abhishek Shakya
 
performance optimization: Memory
晓东 杜
 
Detecting Memory Leaks in Android App
Dinesh Prajapati
 
ACADGILD:: ANDROID LESSON-How to analyze & manage memory on android like ...
Padma shree. T
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
pkoza
 
Profiling JavaScript Performance
Noam Kfir
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Phillip Koza
 
Memory Leaks in Android Applications
Lokesh Ponnada
 
Android Memory Management
Sadmankabirsoumik
 
Memory Heap Analysis with AppDynamics - AppSphere16
AppDynamics
 
MC0078 SMU 2013 Fall session
Narinder Kumar
 
Postmortem of a uwp xaml application development
David Catuhe
 
JAVA INTRODUCTION
Prof Ansari
 
JAVA INTRODUCTION
Prof Ansari
 
Short notes of oop with java
Mohamed Fathy
 
Javasession10
Rajeev Kumar
 
Java Developer Roadmap PDF By ScholarHat
Scholarhat
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
sidg75
 
20 most important java programming interview questions
Gradeup
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Ashish Bhasin
 
CAR SHOWROOM SYSTEM
Abhishek Shakya
 
Ad

More from Mindfire Solutions (20)

PDF
Physician Search and Review
Mindfire Solutions
 
PDF
diet management app
Mindfire Solutions
 
PDF
Business Technology Solution
Mindfire Solutions
 
PDF
Remote Health Monitoring
Mindfire Solutions
 
PDF
Influencer Marketing Solution
Mindfire Solutions
 
PPT
High Availability of Azure Applications
Mindfire Solutions
 
PPTX
IOT Hands On
Mindfire Solutions
 
PPTX
Glimpse of Loops Vs Set
Mindfire Solutions
 
ODP
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
PPT
Adaptive Layout In iOS 8
Mindfire Solutions
 
PPT
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
PPT
LINQPad - utility Tool
Mindfire Solutions
 
PPT
Get started with watch kit development
Mindfire Solutions
 
PPTX
Swift vs Objective-C
Mindfire Solutions
 
ODP
Material Design in Android
Mindfire Solutions
 
ODP
Introduction to OData
Mindfire Solutions
 
PPT
Ext js Part 2- MVC
Mindfire Solutions
 
PPT
ExtJs Basic Part-1
Mindfire Solutions
 
PPT
Spring Security Introduction
Mindfire Solutions
 
Physician Search and Review
Mindfire Solutions
 
diet management app
Mindfire Solutions
 
Business Technology Solution
Mindfire Solutions
 
Remote Health Monitoring
Mindfire Solutions
 
Influencer Marketing Solution
Mindfire Solutions
 
High Availability of Azure Applications
Mindfire Solutions
 
IOT Hands On
Mindfire Solutions
 
Glimpse of Loops Vs Set
Mindfire Solutions
 
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
Adaptive Layout In iOS 8
Mindfire Solutions
 
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
LINQPad - utility Tool
Mindfire Solutions
 
Get started with watch kit development
Mindfire Solutions
 
Swift vs Objective-C
Mindfire Solutions
 
Material Design in Android
Mindfire Solutions
 
Introduction to OData
Mindfire Solutions
 
Ext js Part 2- MVC
Mindfire Solutions
 
ExtJs Basic Part-1
Mindfire Solutions
 
Spring Security Introduction
Mindfire Solutions
 

Recently uploaded (20)

PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 

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.