SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
Java Garbage Collection
Presenter: Rupal Chatterjee, Mindfire Solutions
Date: 27/09/2013
Java Memory Management

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)
The first tier consists of Heap
Stores all created objects in runtime.
PermGen / Method Area
- The segment where the actual compiled Java byte codes resides when loaded.
- Static members (variables or methods) also reside in this segment.
- PermGen is also considered as a part of Heap.
Thread 1..N / Stack
Stores local variables and Reference variables(variables that hold the address of an
object in the heap)

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)
Key Notes 1. Classes (loaded by the class-loaders) go tp Permanent Generation area.
2. All the static member variables are kept on the Permanent Generation area.
3. All variables except the static ones are kept in Stack.
4. Objects created run-time are stored in heap.
5. There is only one copy of each method per class, be the method static or non-static.
That copy is put in the Permanent Generation area.

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)
Key Notes (Contd...) 6. For non-static and static methods, all the parameters and local variables go onto the
stack.
7. The return value of a method get stored in stack.
8. Local variables reside in stack.
– Memory allocated at method invocation time.
– Memory deallocated when method returns.
9. Objects reside in heap.
– Memory is allocated with new keyword.
– But never explicitly deallocated.
10. Java uses a automatic mechanism to free heap memory.

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)

Source: http://blog.pointsoftware.ch

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection
Key Notes 1. It is a mechanism provided by Java Virtual Machine to reclaim heap space from
objects which are eligible for Garbage collection.
2. Garbage collection relieves java programmer from memory management which is
essential part of C++ programming and gives more time to focus on business logic.
3. Garbage Collection in Java is carried by a thread called Garbage Collector.
4. Before removing an object from memory, Garbage collection thread invokes finalize()
method of that object and gives an opportunity to perform any sort of custom cleanup
required.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
Key Notes (Contd...) 5. Programmer can not force Garbage collection in Java; it will only trigger if JVM thinks
it needs a garbage collection based on Java heap size.
6. There are methods like System.gc() and Runtime.gc() which is used to send request
of Garbage collection to JVM but it’s not guaranteed that garbage collection will be
triggered right away.
7. If there is no memory space present for creating new objects in Heap, Java Virtual
Machine throws OutOfMemoryError or java.lang.OutOfMemoryError.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
When an Object becomes Eligible for Garbage Collection
If its not reachable from any references, in other words you can say that an object
becomes eligible for garbage collection if its all references are null.
Cyclic dependencies are not counted as reference so if Object A has reference of
Object B and Object B has reference of Object A and they don't have any other live
reference then both Objects A and B will be eligible for Garbage collection.
Generally an object becomes eligible for garbage collection in Java on following cases:
1) All references of that object explicitly set to null e.g. object = null
2) Object is created inside a block and reference goes out of scope once control exit that
block.
3) Parent object set to null, if an object holds reference of another object and parent
object's reference set to null, child objects automatically becomes eligible for garbage
collection.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
How it works?
Java objects are created in Heap and Heap is divided into two parts or generations for
sake of garbage collection in Java, these are called as Young Generation and Tenured
or Old Generation.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
How it works? (Contd...)
Young Generation is further divided into three parts.
- Eden space,
- From Space (Survivor 1)
- To Space (Survivor 2)
When an object first created,
1) It gets into Young Generation inside Eden space.
2) After subsequent Minor Garbage Collection, if object survives it gets moved to
From Space / Survivor 1.
3) Then to To Space / Survivor 2.
4) Then eventually object moved to Old or Tenured Generation.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
How it works? (Contd...)
Young Generation is where all new objects are allocated and aged. When the young
generation fills up, this causes a minor garbage collection. Some surviving objects are
aged and eventually move to the old generation.
Stop the World Event - All minor garbage collections are "Stop the World" events.
This means that all application threads are stopped until the operation completes.
The Old Generation is used to store long surviving objects. Typically, a threshold is set
for young generation object and when that age is met, the object gets moved to the old
generation. Eventually the old generation needs to be collected. This event is called a
major garbage collection.
Major garbage collection are also Stop the World events. Often a major collection is
much slower.
(extract from Oracle site)

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors
The Serial GC
1. The serial collector is the default GC in Java SE 5 and 6.
2. Here both minor and major garbage collections are done using a single Thread.
3. It uses a mark-compact collection method.
4. Compacting of memory makes it faster to allocate new chunks of memory to the heap.
5. The Serial GC is the choice for most applications that do not have low pause time
requirements.
6. To enable the Serial Collector use: -XX:+UseSerialGC
Here is a sample command line for starting a sample JAR:
java -XX:+UseSerialGC -jar GcTest.jar
Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The Parallel GC
1. The parallel GC uses multiple threads to perform minor garbage collections.
2. By default on a host with N CPUs, the parallel GC uses N GC threads in the
collection.
3. The number of GC threads can be controlled with command-line options:
-XX:ParallelGCThreads=<desired number>.
4. On a host with a single CPU the default GC is used even if the parallel GC has been
requested.
5. On a host with two CPUs the parallel GC generally performs as well as the default
GC.

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The Parallel GC (Contd...)
6.. Reduction in the young generation GC pause times can be expected on hosts with
more than two CPUs.
7. There are two ways to enable Parallel GC,
-XX:+UseParallelGC, With this command line option you get a multi-thread young
GC with a single-threaded old GC.
-XX:+UseParallelOldGC, With this option, you get both a multi-threaded young GC
and multi-threaded old GC.

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The Concurrent Mark Sweep (CMS) Collector
1. It collects the old / tenured generation.
2. Here garbage collection is done concurrently with the application thread. Hence it
reduces the pause time.
3. As it works with live object, compacting is not done here.
4. CMS collectors are used for applications which require low pause time.
5. To enable the CMS Collector use: -XX:+UseConcMarkSweepGC
6. To set the number of threads use: -XX:ParallelCMSThreads=<n>
Here is a sample command line for starting a sample JAR:
java -XX:+UseConcMarkSweepGC -XX:ParallelCMSThreads=2 -jar GcTest.jar

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The G1 Garbage Collector
1. The Garbage First or G1 garbage collector is available in Java 7.
2. It is designed to be the long term replacement for the CMS collector.
3. The G1 collector is a parallel, concurrent, and compacting low-pause garbage
collector.
4. To enable the G1 Collector use: -XX:+UseG1GC
Here is a sample command line for starting a sample JAR:
java -XX:+UseG1GC -jar GcTest.jar

Presenter: Rupal Chatterjee, Mindfire Solutions
Full GC And Concurrent GC
1. Concurrent GC in java runs concurrently with the application threads.
2. The goal is to complete the collection of Tenured Generation before it becomes full.
3. If the Concurrent GC fails to finish before the Tenured Generation fill up. Then?
4. The application will be paused and the collection is completed with all the application
threads stopped.
5. Such collections with the application stopped are referred as Full GC.
6. Full GC affects performance of Java applications.

Presenter: Rupal Chatterjee, Mindfire Solutions
Summary on Garbage collection in Java
1. Java Heap is divided into three generation for sake of garbage collection. These are
Young Generation, Tenured or Old Generation and PermGen.
2. New objects are created in Young Generation and subsequently moved to Old
Generation.
3. Minor GC is used to move object from Eden space to Survivor 1 and Survivor 2
space and then to Tenured Generation.
4. Whenever Major GC occurs application threads stops during that period, which will
reduce application’s performance.
5. JVM command line options –Xmx and -Xms is used to setup min and max size for
Java Heap. Ideal ratio of this parameter is either 1:1 or 1:1.5.
6. There is no manual way of doing garbage collection in Java.

Presenter: Rupal Chatterjee, Mindfire Solutions
Question and
Answer

Presenter: Rupal Chatterjee, Mindfire Solutions
Thank you

Presenter: Rupal Chatterjee, Mindfire Solutions

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
java Features
java Featuresjava Features
java Features
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 
Applets
AppletsApplets
Applets
 
Java threads
Java threadsJava threads
Java threads
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Finalize() method
Finalize() methodFinalize() method
Finalize() method
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 

Andere mochten auch

Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage CollectionAzul Systems Inc.
 
An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAbhishek Asthana
 
Garbage collection in JVM
Garbage collection in JVMGarbage collection in JVM
Garbage collection in JVMaragozin
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItAzul Systems Inc.
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage CollectionDoug Hawkins
 
Java Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningJava Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningCarol McDonald
 
Java Garbage Collection
Java Garbage CollectionJava Garbage Collection
Java Garbage CollectionVinay H G
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20Niit Care
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16Niit Care
 
Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09Niit Care
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13Niit Care
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01Niit Care
 
Garbage collection algorithms
Garbage collection algorithmsGarbage collection algorithms
Garbage collection algorithmsachinth
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19Niit Care
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_cNiit Care
 

Andere mochten auch (20)

Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage Collection
 
An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in Java
 
Garbage collection in JVM
Garbage collection in JVMGarbage collection in JVM
Garbage collection in JVM
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About It
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
 
Java Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningJava Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and Tuning
 
Java Garbage Collection
Java Garbage CollectionJava Garbage Collection
Java Garbage Collection
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20
 
Oops recap
Oops recapOops recap
Oops recap
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16
 
 
Dacj 2-2 c
Dacj 2-2 cDacj 2-2 c
Dacj 2-2 c
 
Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01
 
Rdbms xp 01
Rdbms xp 01Rdbms xp 01
Rdbms xp 01
 
Garbage collection algorithms
Garbage collection algorithmsGarbage collection algorithms
Garbage collection algorithms
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_c
 

Ähnlich wie Java Garbage Collection - How it works

Garbage Collection in Java.pdf
Garbage Collection in Java.pdfGarbage Collection in Java.pdf
Garbage Collection in Java.pdfSudhanshiBakre1
 
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance TuningProfiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuningosa_ora
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4aminmesbahi
 
Garbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMGarbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMjaganmohanreddyk
 
Jvm performance tuning
Jvm performance tuningJvm performance tuning
Jvm performance tuningIgor Igoroshka
 
Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performanceRoger Xia
 
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)Prashanth Kumar
 
Memory Leaks in Android Applications
Memory Leaks in Android ApplicationsMemory Leaks in Android Applications
Memory Leaks in Android ApplicationsLokesh Ponnada
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
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 R12sidg75
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK toolsHaribabu Nandyal Padmanaban
 
Learn Microsoft Asp.Net Garbage Collection
Learn Microsoft Asp.Net Garbage CollectionLearn Microsoft Asp.Net Garbage Collection
Learn Microsoft Asp.Net Garbage CollectionDiya Singh
 
Garbage collector complete information
Garbage collector complete informationGarbage collector complete information
Garbage collector complete informationMubarak Hussain
 
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 ApplicationsPhillip Koza
 
Why using finalizers is a bad idea
Why using finalizers is a bad ideaWhy using finalizers is a bad idea
Why using finalizers is a bad ideaPVS-Studio
 
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 UsageJelastic Multi-Cloud PaaS
 
A novel design of a parallel machine learnt
A novel design of a parallel machine learntA novel design of a parallel machine learnt
A novel design of a parallel machine learntcseij
 
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector A Novel Design of a Parallel Machine Learnt Generational Garbage Collector
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector cseij
 

Ähnlich wie Java Garbage Collection - How it works (20)

Garbage Collection in Java.pdf
Garbage Collection in Java.pdfGarbage Collection in Java.pdf
Garbage Collection in Java.pdf
 
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance TuningProfiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
 
Javasession10
Javasession10Javasession10
Javasession10
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4
 
Garbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMGarbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVM
 
Jvm performance tuning
Jvm performance tuningJvm performance tuning
Jvm performance tuning
 
Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performance
 
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)
 
Memory Leaks in Android Applications
Memory Leaks in Android ApplicationsMemory Leaks in Android Applications
Memory Leaks in Android Applications
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
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
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Learn Microsoft Asp.Net Garbage Collection
Learn Microsoft Asp.Net Garbage CollectionLearn Microsoft Asp.Net Garbage Collection
Learn Microsoft Asp.Net Garbage Collection
 
Garbage collector complete information
Garbage collector complete informationGarbage collector complete information
Garbage collector complete information
 
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
 
Why using finalizers is a bad idea
Why using finalizers is a bad ideaWhy using finalizers is a bad idea
Why using finalizers is a bad idea
 
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
 
A novel design of a parallel machine learnt
A novel design of a parallel machine learntA novel design of a parallel machine learnt
A novel design of a parallel machine learnt
 
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector A Novel Design of a Parallel Machine Learnt Generational Garbage Collector
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector
 

Mehr von 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
 

Kürzlich hochgeladen

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Kürzlich hochgeladen (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

Java Garbage Collection - How it works

  • 1. Java Garbage Collection Presenter: Rupal Chatterjee, Mindfire Solutions Date: 27/09/2013
  • 2. Java Memory Management Presenter: Rupal Chatterjee, Mindfire Solutions
  • 3. Java Memory Management (Contd...) The first tier consists of Heap Stores all created objects in runtime. PermGen / Method Area - The segment where the actual compiled Java byte codes resides when loaded. - Static members (variables or methods) also reside in this segment. - PermGen is also considered as a part of Heap. Thread 1..N / Stack Stores local variables and Reference variables(variables that hold the address of an object in the heap) Presenter: Rupal Chatterjee, Mindfire Solutions
  • 4. Java Memory Management (Contd...) Key Notes 1. Classes (loaded by the class-loaders) go tp Permanent Generation area. 2. All the static member variables are kept on the Permanent Generation area. 3. All variables except the static ones are kept in Stack. 4. Objects created run-time are stored in heap. 5. There is only one copy of each method per class, be the method static or non-static. That copy is put in the Permanent Generation area. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 5. Java Memory Management (Contd...) Key Notes (Contd...) 6. For non-static and static methods, all the parameters and local variables go onto the stack. 7. The return value of a method get stored in stack. 8. Local variables reside in stack. – Memory allocated at method invocation time. – Memory deallocated when method returns. 9. Objects reside in heap. – Memory is allocated with new keyword. – But never explicitly deallocated. 10. Java uses a automatic mechanism to free heap memory. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 6. Java Memory Management (Contd...) Source: http://blog.pointsoftware.ch Presenter: Rupal Chatterjee, Mindfire Solutions
  • 7. Garbage Collection Key Notes 1. It is a mechanism provided by Java Virtual Machine to reclaim heap space from objects which are eligible for Garbage collection. 2. Garbage collection relieves java programmer from memory management which is essential part of C++ programming and gives more time to focus on business logic. 3. Garbage Collection in Java is carried by a thread called Garbage Collector. 4. Before removing an object from memory, Garbage collection thread invokes finalize() method of that object and gives an opportunity to perform any sort of custom cleanup required. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 8. Garbage Collection (Contd...) Key Notes (Contd...) 5. Programmer can not force Garbage collection in Java; it will only trigger if JVM thinks it needs a garbage collection based on Java heap size. 6. There are methods like System.gc() and Runtime.gc() which is used to send request of Garbage collection to JVM but it’s not guaranteed that garbage collection will be triggered right away. 7. If there is no memory space present for creating new objects in Heap, Java Virtual Machine throws OutOfMemoryError or java.lang.OutOfMemoryError. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 9. Garbage Collection (Contd...) When an Object becomes Eligible for Garbage Collection If its not reachable from any references, in other words you can say that an object becomes eligible for garbage collection if its all references are null. Cyclic dependencies are not counted as reference so if Object A has reference of Object B and Object B has reference of Object A and they don't have any other live reference then both Objects A and B will be eligible for Garbage collection. Generally an object becomes eligible for garbage collection in Java on following cases: 1) All references of that object explicitly set to null e.g. object = null 2) Object is created inside a block and reference goes out of scope once control exit that block. 3) Parent object set to null, if an object holds reference of another object and parent object's reference set to null, child objects automatically becomes eligible for garbage collection. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 10. Garbage Collection (Contd...) How it works? Java objects are created in Heap and Heap is divided into two parts or generations for sake of garbage collection in Java, these are called as Young Generation and Tenured or Old Generation. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 11. Garbage Collection (Contd...) How it works? (Contd...) Young Generation is further divided into three parts. - Eden space, - From Space (Survivor 1) - To Space (Survivor 2) When an object first created, 1) It gets into Young Generation inside Eden space. 2) After subsequent Minor Garbage Collection, if object survives it gets moved to From Space / Survivor 1. 3) Then to To Space / Survivor 2. 4) Then eventually object moved to Old or Tenured Generation. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 12. Garbage Collection (Contd...) How it works? (Contd...) Young Generation is where all new objects are allocated and aged. When the young generation fills up, this causes a minor garbage collection. Some surviving objects are aged and eventually move to the old generation. Stop the World Event - All minor garbage collections are "Stop the World" events. This means that all application threads are stopped until the operation completes. The Old Generation is used to store long surviving objects. Typically, a threshold is set for young generation object and when that age is met, the object gets moved to the old generation. Eventually the old generation needs to be collected. This event is called a major garbage collection. Major garbage collection are also Stop the World events. Often a major collection is much slower. (extract from Oracle site) Presenter: Rupal Chatterjee, Mindfire Solutions
  • 13. Type of Garbage Collectors The Serial GC 1. The serial collector is the default GC in Java SE 5 and 6. 2. Here both minor and major garbage collections are done using a single Thread. 3. It uses a mark-compact collection method. 4. Compacting of memory makes it faster to allocate new chunks of memory to the heap. 5. The Serial GC is the choice for most applications that do not have low pause time requirements. 6. To enable the Serial Collector use: -XX:+UseSerialGC Here is a sample command line for starting a sample JAR: java -XX:+UseSerialGC -jar GcTest.jar Presenter: Rupal Chatterjee, Mindfire Solutions
  • 14. Type of Garbage Collectors (Contd...) The Parallel GC 1. The parallel GC uses multiple threads to perform minor garbage collections. 2. By default on a host with N CPUs, the parallel GC uses N GC threads in the collection. 3. The number of GC threads can be controlled with command-line options: -XX:ParallelGCThreads=<desired number>. 4. On a host with a single CPU the default GC is used even if the parallel GC has been requested. 5. On a host with two CPUs the parallel GC generally performs as well as the default GC. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 15. Type of Garbage Collectors (Contd...) The Parallel GC (Contd...) 6.. Reduction in the young generation GC pause times can be expected on hosts with more than two CPUs. 7. There are two ways to enable Parallel GC, -XX:+UseParallelGC, With this command line option you get a multi-thread young GC with a single-threaded old GC. -XX:+UseParallelOldGC, With this option, you get both a multi-threaded young GC and multi-threaded old GC. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 16. Type of Garbage Collectors (Contd...) The Concurrent Mark Sweep (CMS) Collector 1. It collects the old / tenured generation. 2. Here garbage collection is done concurrently with the application thread. Hence it reduces the pause time. 3. As it works with live object, compacting is not done here. 4. CMS collectors are used for applications which require low pause time. 5. To enable the CMS Collector use: -XX:+UseConcMarkSweepGC 6. To set the number of threads use: -XX:ParallelCMSThreads=<n> Here is a sample command line for starting a sample JAR: java -XX:+UseConcMarkSweepGC -XX:ParallelCMSThreads=2 -jar GcTest.jar Presenter: Rupal Chatterjee, Mindfire Solutions
  • 17. Type of Garbage Collectors (Contd...) The G1 Garbage Collector 1. The Garbage First or G1 garbage collector is available in Java 7. 2. It is designed to be the long term replacement for the CMS collector. 3. The G1 collector is a parallel, concurrent, and compacting low-pause garbage collector. 4. To enable the G1 Collector use: -XX:+UseG1GC Here is a sample command line for starting a sample JAR: java -XX:+UseG1GC -jar GcTest.jar Presenter: Rupal Chatterjee, Mindfire Solutions
  • 18. Full GC And Concurrent GC 1. Concurrent GC in java runs concurrently with the application threads. 2. The goal is to complete the collection of Tenured Generation before it becomes full. 3. If the Concurrent GC fails to finish before the Tenured Generation fill up. Then? 4. The application will be paused and the collection is completed with all the application threads stopped. 5. Such collections with the application stopped are referred as Full GC. 6. Full GC affects performance of Java applications. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 19. Summary on Garbage collection in Java 1. Java Heap is divided into three generation for sake of garbage collection. These are Young Generation, Tenured or Old Generation and PermGen. 2. New objects are created in Young Generation and subsequently moved to Old Generation. 3. Minor GC is used to move object from Eden space to Survivor 1 and Survivor 2 space and then to Tenured Generation. 4. Whenever Major GC occurs application threads stops during that period, which will reduce application’s performance. 5. JVM command line options –Xmx and -Xms is used to setup min and max size for Java Heap. Ideal ratio of this parameter is either 1:1 or 1:1.5. 6. There is no manual way of doing garbage collection in Java. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 20. Question and Answer Presenter: Rupal Chatterjee, Mindfire Solutions
  • 21. Thank you Presenter: Rupal Chatterjee, Mindfire Solutions