{"id":9535,"date":"2020-12-26T14:28:40","date_gmt":"2020-12-26T14:28:40","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=9535"},"modified":"2024-02-16T11:10:42","modified_gmt":"2024-02-16T11:10:42","slug":"garbage-collection-basics","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=9535","title":{"rendered":"Garbage collection (Basics)"},"content":{"rendered":"<p>A garbage collector is a hidden background tool that cleans unused application memory automatically. It&#8217;s necessary for languages which aren&#8217;t providing any way to explicitly deleting created reference objects on the heap, like Java and C#.<\/p>\n<hr>\n<p><strong>Strategies<\/strong><\/p>\n<p><u>1. Reference counting <\/u><br \/>\nFor every reference object it keeps a reference counter and if that hits zero that object gets destroyed.<\/p>\n<p>Adaptation: In C++ smart pointers implementing this strategy, but they have to be used explicitly and they do the reference counting by them self.<\/p>\n<p>Disadvantage: Cyclic references can&#8217;t be resolved automatically.<\/p>\n<p><u>2. Tracing<\/u><br \/>\nIt keeps a graph of the reference objects and if there is no way to a ref. object anymore it destroys it.<\/p>\n<p>Algorithms:<br \/>\n&#8211; Mark-and-Sweep (Fragments the heap)<br \/>\n&#8211; Stop-and-Copy (Consumes much heap)<br \/>\n&#8211; Mark-and-Compact (Defragmentation takes time)<\/p>\n<p>Improvement: Implementation of the concept of generations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A garbage collector is a hidden background tool that cleans unused application memory automatically. It&#8217;s necessary for languages which aren&#8217;t<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[28],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/9535"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9535"}],"version-history":[{"count":1,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/9535\/revisions"}],"predecessor-version":[{"id":16779,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/9535\/revisions\/16779"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9535"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}