{"id":25524385,"date":"2022-05-16T15:19:25","date_gmt":"2022-05-16T09:49:25","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25524385"},"modified":"2022-11-20T08:45:41","modified_gmt":"2022-11-20T03:15:41","slug":"memory-management-and-garbage-collection-in-java","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/","title":{"rendered":"Memory Management And Garbage Collection In Java"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69ea30c170d42\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69ea30c170d42\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#Memory_Management\" >Memory Management<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#Garbage_Collection\" >Garbage Collection<\/a><\/li><\/ul><\/nav><\/div>\n<p>Java Memory Management, with its built-in garbage collection, is one of the language\u2019s finest achievements. It allows developers to create new objects without worrying explicitly about memory allocation and deallocation, because the garbage collector automatically reclaims memory for reuse. This enables faster development with less boilerplate code, while eliminating memory leaks and other memory-related problems.<\/p>\n<p data-selectable-paragraph=\"\">Ironically, Java garbage collection seems to work too well, creating and removing too many objects. Most memory-management issues are solved, but often at the cost of creating serious performance problems. Making garbage collection adaptable to all kinds of situations has led to a complex and hard-to-optimize system. In order to wrap your head around garbage collection, you need first to understand how memory management works in a Java Virtual Machine (JVM).<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Memory_Management\"><\/span><strong>Memory Management<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Memory management is the process of allocating new objects and removing unused objects to make space for those new object allocations. This section presents some basic memory management concepts and explains the basics about object allocation and garbage collection in the Oracle JRockit JVM.<\/p>\n<ul>\n<li>The Heap and the Nursery<\/li>\n<li>Object Allocation<\/li>\n<li>Garbage Collection<\/li>\n<\/ul>\n<h3><strong>The Heap and the Nursery<\/strong><\/h3>\n<p>Java objects reside in an area called\u00a0the heap. The heap is created when the JVM starts up and may increase or decrease in size while the application runs. When the heap becomes full,\u00a0garbage\u00a0is\u00a0collected.\u00a0During the garbage collection objects that are no longer used are cleared, thus making space for new objects.<\/p>\n<p>Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.<\/p>\n<p>The heap is sometimes divided into two areas (or\u00a0generations) called the\u00a0nursery\u00a0(or\u00a0young space) and the\u00a0old space. The nursery is a part of the heap reserved for allocation of new objects. When the nursery becomes full, garbage is collected by running a special\u00a0young collection, where all objects that have lived long enough in the nursery are\u00a0promoted\u00a0(moved) to the old space, thus freeing up the nursery for more object allocation. When the old space becomes full garbage is collected there, a process called an\u00a0old collection.<\/p>\n<p>The reasoning behind a nursery is that most objects are temporary and short lived. A young collection is designed to be swift at finding newly allocated objects that are still alive and moving them away from the nursery. Typically, a young collection frees a given amount of memory much faster than an old collection or a garbage collection of a single-generational heap (a heap without a nursery).<\/p>\n<h3><strong>Object Allocation<\/strong><\/h3>\n<p>During object allocation, the JRockit JVM distinguishes between\u00a0small\u00a0and\u00a0large\u00a0objects. The limit for when an object is considered large depends on the JVM version, the heap size, the garbage collection strategy and the platform used, but is usually somewhere between 2 and 128 kB.<\/p>\n<p>Small objects are allocated in\u00a0thread local areas\u00a0(TLAs). The thread local areas are free chunks reserved from the heap and given to a Java thread for exclusive use. The thread can then allocate objects in its TLA without synchronizing with other threads. When the TLA becomes full, the thread simply requests a new TLA. The TLAs are reserved from the nursery if such exists, otherwise they are reserved anywhere in the heap.<\/p>\n<p>Large objects that don\u2019t fit inside a TLA are allocated directly on the heap. When a nursery is used, the large objects are allocated directly in old space. Allocation of large objects requires more synchronization between the Java threads, although the JRockit JVM uses a system of caches of free chunks of different sizes to reduce the need for synchronization and improve the allocation speed.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Garbage_Collection\"><\/span><strong>Garbage Collection<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Java garbage collection is the process by which Java programs perform automatic memory management. Java programs compile to bytecode that can be run on a Java Virtual Machine, or JVM for short. When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Learn Coding in your Language! Enroll Here!<\/a><\/strong><\/p>\n<h3><strong>How Java Garbage Collection Works<\/strong><\/h3>\n<p>Java garbage collection is an automatic process. The programmer does not need to explicitly mark objects to be deleted. The garbage collection implementation lives in the JVM. Each JVM can implement garbage collection however it pleases; the only requirement is that it meets the JVM specification. Although there are many JVMs, Oracle\u2019s HotSpot is by far the most common. It offers a robust and mature set of garbage collection options.<\/p>\n<p>While HotSpot has multiple garbage collectors that are optimized for various use cases, all its garbage collectors follow the same basic process. In the first step,\u00a0unreferenced objects\u00a0are identified and marked as ready for garbage collection. In the second step, marked objects are deleted. Optionally, memory can be compacted after the garbage collector deletes objects, so remaining objects are in a contiguous block at the start of the heap. The compaction process makes it easier to allocate memory to new objects sequentially after the block of memory allocated to existing objects.<\/p>\n<p>All of HotSpot\u2019s garbage collectors implement a generational garbage collection strategy that categorizes objects by age. The rationale behind generational garbage collection is that most objects are short-lived and will be ready for garbage collection soon after creation.<\/p>\n<p>The heap is divided into\u00a0three sections:<\/p>\n<ul>\n<li><strong>Young Generation<\/strong>: Newly created objects start in the Young Generation. The Young Generation is further subdivided into an Eden space, where all new objects start, and two Survivor spaces, where objects are moved from Eden after surviving one garbage collection cycle. When objects are garbage collected from the Young Generation, it is a minor garbage collection event.<\/li>\n<li><strong>Old Generation:<\/strong>Objects that are long-lived are eventually moved from the Young Generation to the Old Generation. When objects are garbage collected from the Old Generation, it is a major garbage collection event.<\/li>\n<li><strong>Permanent Generation:<\/strong>Metadata such as classes and methods are stored in the Permanent Generation. Classes that are no longer in use may be garbage collected from the Permanent Generation.<\/li>\n<\/ul>\n<p>During a full garbage collection event, unused objects in all generations are garbage collected.<\/p>\n<p>HotSpot has four garbage collectors:<\/p>\n<ul>\n<li><strong>Serial:<\/strong>All garbage collection events are conducted serially in one thread. Compaction is executed after each garbage collection.<\/li>\n<li><strong>Parallel:<\/strong>Multiple threads are used for minor garbage collection. A single thread is used for major garbage collection and Old Generation compaction. Alternatively, the Parallel Old variant uses multiple threads for major garbage collection and Old Generation compaction.<\/li>\n<li><strong>CMS (Concurrent Mark Sweep):<\/strong>Multiple threads are used for minor garbage collection using the same algorithm as Parallel. Major garbage collection is multi-threaded, like Parallel Old, but CMS runs concurrently alongside application processes to minimize \u201cstop the world\u201d events (i.e. when the garbage collector running stops the application). No compaction is performed.<\/li>\n<li><strong>G1 (Garbage First):<\/strong>The newest garbage collector is intended as a replacement for CMS. It is parallel and concurrent like CMS, but it works quite differently under the hood compared to the older garbage collectors.<\/li>\n<\/ul>\n<h3><strong>Benefits of Java Garbage Collection<\/strong><\/h3>\n<p>The biggest benefit of Java garbage collection is that it automatically handles the deletion of unused objects or objects that are\u00a0out of reach\u00a0to free up vital memory resources.\u00a0Programmers working in languages without garbage collection (like C and C++) must implement manual memory management in their code.<\/p>\n<p>Garbage collection is the process of freeing space in the heap or the nursery for allocation of new objects. This section describes the garbage collection in the JRockit JVM.<\/p>\n<ul>\n<li>The Mark and Sweep Model<\/li>\n<li>Generational Garbage Collection<\/li>\n<li>Dynamic and Static Garbage Collection Modes<\/li>\n<li>Compaction<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/p>\n<h4><strong>The Mark and Sweep Model<\/strong><\/h4>\n<p>The JRockit JVM uses the\u00a0mark and sweep\u00a0garbage collection model for performing garbage collections of the whole heap. A mark and sweep garbage collection consists of two phases, the\u00a0mark phase\u00a0and the\u00a0sweep phase.<\/p>\n<p>During the mark phase all objects that are reachable from Java threads, native handles and other root sources are\u00a0marked\u00a0as alive, as well as the objects that are reachable from these objects and so forth. This process identifies and marks all objects that are still used, and the rest can be considered garbage.<\/p>\n<p>During the sweep phase the heap is traversed to find the gaps between the live objects. These gaps are recorded in a\u00a0free list\u00a0and are made available for new object allocation.<\/p>\n<p>The JRockit JVM uses two improved versions of the mark and sweep model. One is\u00a0mostly concurrent mark and sweep\u00a0and the other is\u00a0parallel mark and sweep. You can also mix the two strategies, running for example mostly concurrent mark and parallel sweep.<\/p>\n<h4><strong>Generational Garbage Collection<\/strong><\/h4>\n<p>The nursery, when it exists, is garbage collected with a special garbage collection called a\u00a0young collection. A garbage collection strategy which uses a nursery is called a generational garbage collection strategy, or simply\u00a0generational garbage collection.<\/p>\n<p>The young collector used in the JRockit JVM identifies and promotes all live objects in the nursery that are outside the keep area to the old space. This work is done in parallel using all available CPUs. The Java threads are paused during the entire young collection.<\/p>\n<h4><strong>Dynamic and Static Garbage Collection Modes<\/strong><\/h4>\n<p>By default, the JRockit JVM uses a dynamic garbage collection mode that automatically selects a garbage collection strategy to use, aiming at optimizing the application throughput. You can also choose between two other dynamic garbage collection modes or select the garbage collection strategy statically. The following dynamic modes are available:<\/p>\n<ul>\n<li>throughput, which optimizes the garbage collector for maximum application throughput. This is the default mode.<\/li>\n<li>pausetime, which optimizes the garbage collector for short and even pause times.<\/li>\n<li>deterministic, which optimizes the garbage collector for very short and deterministic pause times. This mode is only available as a part of Oracle JRockit Real Time.<\/li>\n<\/ul>\n<p>The major static strategies are:<\/p>\n<ul>\n<li>singlepar, which is a single-generational parallel garbage collector (same as\u00a0parallel)<\/li>\n<li>genpar, which is a two-generational parallel garbage collector<\/li>\n<li>singlecon, which is a single-generational mostly concurrent garbage collector<\/li>\n<li>gencon, which is a two-generational mostly concurrent garbage collector<\/li>\n<\/ul>\n<p>For more information on how to select the best mode or strategy for your application, see\u00a0Selecting and Tuning a Garbage Collector.<\/p>\n<h4><strong>Compaction<\/strong><\/h4>\n<p>Objects that are allocated next to each other will not necessarily become unreachable (\u201cdie\u201d) at the same time. This means that the heap may become fragmented after a garbage collection, so that the free spaces in the heap are many but small, making allocation of large objects hard or even impossible. Free spaces that are smaller than the minimum thread local area (TLA) size can not be used at all, and the garbage collector discards them as\u00a0dark matter\u00a0until a future garbage collection frees enough space next to them to create a space large enough for a TLA.<\/p>\n<p>To reduce fragmentation, the JRockit JVM compacts a part of the heap at every garbage collection (old collection). Compaction moves objects closer together and further down in the heap, thus creating larger free areas near the top of the heap. The size and position of the compaction area as well as the compaction method is selected by advanced heuristics, depending on the garbage collection mode used.<\/p>\n<p>Compaction is performed at the beginning of or during the sweep phase and while all Java threads are paused.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522670 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"Python and Machine Learning Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<p><strong>Why is it important to choose Entri?<\/strong><\/p>\n<ul>\n<li>Excellent online platform for all the Competitive Exams.<\/li>\n<li>Provides updated materials created by the Entri Experts.<\/li>\n<li>Entri provides a best platform with full- length mock tests including previous year question papers.<\/li>\n<li>You can download the app for free and join the required classes.<\/li>\n<li>Entri wishes you all the best for your examinations and future endeavours.<\/li>\n<\/ul>\n<p><strong>\u201cYOU DON\u2019T HAVE TO BE GREAT TO START, BUT YOU HAVE TO START TO BE GREAT.\u201d<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java Memory Management, with its built-in garbage collection, is one of the language\u2019s finest achievements. It allows developers to create new objects without worrying explicitly about memory allocation and deallocation, because the garbage collector automatically reclaims memory for reuse. This enables faster development with less boilerplate code, while eliminating memory leaks and other memory-related problems. [&hellip;]<\/p>\n","protected":false},"author":55,"featured_media":25524387,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1882],"tags":[],"class_list":["post-25524385","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-java-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Memory Management And Garbage Collection In Java - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Memory Management And Garbage Collection In Java - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"Java Memory Management, with its built-in garbage collection, is one of the language\u2019s finest achievements. It allows developers to create new objects without worrying explicitly about memory allocation and deallocation, because the garbage collector automatically reclaims memory for reuse. This enables faster development with less boilerplate code, while eliminating memory leaks and other memory-related problems. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-16T09:49:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-20T03:15:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ayesha Surayya\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ayesha Surayya\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/\"},\"author\":{\"name\":\"Ayesha Surayya\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/568cc9d6e77fd5d01033b61c88343097\"},\"headline\":\"Memory Management And Garbage Collection In Java\",\"datePublished\":\"2022-05-16T09:49:25+00:00\",\"dateModified\":\"2022-11-20T03:15:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/\"},\"wordCount\":2018,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png\",\"articleSection\":[\"Articles\",\"Java Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/\",\"url\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/\",\"name\":\"Memory Management And Garbage Collection In Java - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png\",\"datePublished\":\"2022-05-16T09:49:25+00:00\",\"dateModified\":\"2022-11-20T03:15:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png\",\"width\":820,\"height\":615,\"caption\":\"Memory Management And Garbage Collection In Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Entri Skilling\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Memory Management And Garbage Collection In Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/568cc9d6e77fd5d01033b61c88343097\",\"name\":\"Ayesha Surayya\",\"url\":\"https:\/\/entri.app\/blog\/author\/ayesha-surayya\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Memory Management And Garbage Collection In Java - Entri Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Memory Management And Garbage Collection In Java - Entri Blog","og_description":"Java Memory Management, with its built-in garbage collection, is one of the language\u2019s finest achievements. It allows developers to create new objects without worrying explicitly about memory allocation and deallocation, because the garbage collector automatically reclaims memory for reuse. This enables faster development with less boilerplate code, while eliminating memory leaks and other memory-related problems. [&hellip;]","og_url":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-05-16T09:49:25+00:00","article_modified_time":"2022-11-20T03:15:41+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png","type":"image\/png"}],"author":"Ayesha Surayya","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Ayesha Surayya","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/"},"author":{"name":"Ayesha Surayya","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/568cc9d6e77fd5d01033b61c88343097"},"headline":"Memory Management And Garbage Collection In Java","datePublished":"2022-05-16T09:49:25+00:00","dateModified":"2022-11-20T03:15:41+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/"},"wordCount":2018,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png","articleSection":["Articles","Java Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/","url":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/","name":"Memory Management And Garbage Collection In Java - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png","datePublished":"2022-05-16T09:49:25+00:00","dateModified":"2022-11-20T03:15:41+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Memory-Management-And-Garbage-Collection-In-Java.png","width":820,"height":615,"caption":"Memory Management And Garbage Collection In Java"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/memory-management-and-garbage-collection-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Entri Skilling","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/"},{"@type":"ListItem","position":3,"name":"Java Programming","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/"},{"@type":"ListItem","position":4,"name":"Memory Management And Garbage Collection In Java"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/568cc9d6e77fd5d01033b61c88343097","name":"Ayesha Surayya","url":"https:\/\/entri.app\/blog\/author\/ayesha-surayya\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25524385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25524385"}],"version-history":[{"count":4,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25524385\/revisions"}],"predecessor-version":[{"id":25547534,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25524385\/revisions\/25547534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25524387"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25524385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25524385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25524385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}