ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Garbage Collection in Java | Types | How It works | Example

garbage collection in java

what is garbage collection in java

how garbage collection work in java

what is serial garbage collection

what is parallel garbage collection

what is concurrent mark and sweep collection

java interview questions on garbage collections

How garbage collection works in Java

Types of garbage collector in Java

Garbage collection in Java example

code decode java interview questions

Автор: Coding World

Загружено: 2023-01-29

Просмотров: 5444

Описание: Garbage Collector Internal working

Blogger : https://javainterviewsworld.blogspot....

1.What is garbage collection


It is the process of removing unused object from java heap area and making heap space empty for use


In c and c++ programmer is responsible for destroy of created object


But in java it is given to jvm


We can call garbage collection using


Finalise method

system.gc() method call


But it will not give guarantee that it will call the garbage collector.


When you run your program on jvm . Objects get created in heap areas.

Some of them are used in application for long time but some are for short period

Those short period objects occupy space from the heap area.


Below scenarios can create objects for short time period


Test t1= new Test()

t1=null


Test t1= new Test();

Test t2=new Test();

t1=t2;



return (new Test)


How does Garbage Collection Work in Java?
It is an automatic process handled by JVM. it specify all its standard and according to that it gets called

It scan all heap memory and unreachable object gets garbage collected



Phases of Garbage Collection in Java
A standard Garbage Collection implementation involves three phases

1.Mark all referenced objects




2. Sweep dead Objects


All the non referenced objects gets destroyed.


3.Compact remaining space by arranging objects


To make all remaining objects in continuous formats


Heap Memory is divided into below area’s




Young generation

Eden space - all new objects start here, and initial memory is allocated to them

Survivor spaces (s0 and s1) - objects are moved here from Eden after surviving one garbage collection cycle.

You can use the -Xmn flag to set the size of the Young Generation.

Old Generation
Objects that are long-lived are eventually moved from the Young Generation to the Old Generation. This is also known as Tenured Generation, and contains objects that have remained in the survivor spaces for a long time

When objects are garbage collected from the Old Generation, it is a major garbage collection event.

You can use the -Xms and -Xmx flags to set the size of the initial and maximum size of the Heap memory.


Permanent Generation
It store meta information about classes and methods used while running applications

You can use the -XX:PermGen and -XX:MaxPermGen flags to set the initial and maximum size of the Permanent Generation.

Also String constant pool is reciting in Perm gen memory area

MetaSpace
Starting with Java 8, the MetaSpace memory space replaces the PermGen space. The implementation differs from the PermGen and this space of the heap is now automatically resized.

It is used to avoid memory out of exception

Type of GC

Serial GC



only one thread is used to collect all garbage from all phase of memory

It is stop world event ,where all threads in application stops and only GC thread runs

It is very difficult for application which has low latency

Eg. Share market

2.Parallel GC

Where multiple threads simultaneously collect garbage.

This is the default implementation of GC in the JVM and is also known as Throughput Collector





3.CMS (Concurrent Mark Sweep) GC

CMS runs concurrently alongside application processes to minimise “stop the world” events.



Due to both application and GC threads running simultaneously it consumes more memory.

4. G1 (Garbage First) GC

It is parallel and concurrent like CMS, but it works quite differently under the hood compared to the older garbage collectors.

It divide your heap into multiple similar blocks according to your heap memory and scan parallel those blocks

After the mark phase is completed, G1 knows which regions contain the most garbage objects. If the user is interested in minimal pause times, G1 can choose to evacuate only a few regions. If the user is not worried about pause times or has stated a fairly large pause-time goal, G1 might choose to include more regions.

Since G1GC identifies the regions with the most garbage and performs garbage collection on that region first, it is called Garbage First

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Garbage Collection in Java | Types | How It works | Example

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

Java telephonic interview |  questions and answers for 7 year experienced candidate | infosys

Java telephonic interview | questions and answers for 7 year experienced candidate | infosys

Garbage Collection in Java | What is GC and How does it Work in the JVM? | Types of GCs | Geekific

Garbage Collection in Java | What is GC and How does it Work in the JVM? | Types of GCs | Geekific

Java's Garbage Collection Explained - How It Saves your Lazy Programmer Butt

Java's Garbage Collection Explained - How It Saves your Lazy Programmer Butt

Top 10 Interview Questions on Garbage Collection | Mark and Sweep Algorithm? Major vs Minor GC

Top 10 Interview Questions on Garbage Collection | Mark and Sweep Algorithm? Major vs Minor GC

Тебе ВРАЛИ про IT! Мифы, которые мешают стать программистом

Тебе ВРАЛИ про IT! Мифы, которые мешают стать программистом

«Будем жить!» | Хитрая передача на Первом канале о вернувшихся с СВО (English subtitles) @Max_Katz

«Будем жить!» | Хитрая передача на Первом канале о вернувшихся с СВО (English subtitles) @Max_Katz

Лекция 12. Барьеры памяти. Модели памяти

Лекция 12. Барьеры памяти. Модели памяти

Эксперт по кибербезопасности о ваших паролях, вирусах и кибератаках

Эксперт по кибербезопасности о ваших паролях, вирусах и кибератаках

Похудей на 45 КГ, Выиграй $250,000!

Похудей на 45 КГ, Выиграй $250,000!

Хочешь в IT? Удели Мне 49 Мин - Я Сэкономлю Тебе ГОДЫ

Хочешь в IT? Удели Мне 49 Мин - Я Сэкономлю Тебе ГОДЫ

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]