{"id":478,"date":"2011-07-08T22:33:00","date_gmt":"2011-07-08T22:33:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/low-gc-in-java-use-primitives-instead-of-wrappers.html"},"modified":"2012-10-21T20:01:23","modified_gmt":"2012-10-21T20:01:23","slug":"low-gc-in-java-use-primitives-instead","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html","title":{"rendered":"Low GC in Java: Use primitives instead of wrappers"},"content":{"rendered":"<p><span class=\"Apple-style-span\" style=\"font-size: large\"><strong>Overview<\/strong><\/span><br \/>\nThere are two good reason to use primitives instead of wrappers where possible.<\/p>\n<ul>\n<li>Clarity. By using a primitive, you are making it clear that a null value is not appropriate.<\/li>\n<li>Performance. Using primitives is often much faster.<\/li>\n<\/ul>\n<p>Clarity is often more important than performance, and is the best reason to use them. However, this article discussed the performance implications of using wrappers.<\/p>\n<p>I have had a lot of interest in this article <a href=\"http:\/\/vanillajava.blogspot.com\/2011\/06\/how-to-avoid-garbage-collection.html\">How to avoid Garbage Collection<\/a>, however this was lacking in much practical detail. This is the first article in a series on ways to reduce demands on the GC.<\/p>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Performance of using wrappers<\/span><\/strong><br \/>\nThe following micro-benchmark behaves in a way many application do.<\/p>\n<p><i>Loop using Wrappers and Wrapper Collection<\/i><\/p>\n<pre class=\"brush:java\">Map&lt;Integer, Integer&gt; counters = new HashMap&lt;Integer, Integer&gt;();\r\nint runs = 20 * 1000;\r\nfor (Integer i = 0; i &lt; runs; i++) {\r\n    Integer x = i % 12;\r\n    Integer y = i \/ 12 % 12;\r\n    Integer times = x * y;\r\n    Integer count = counters.get(times);\r\n    if (count == null)\r\n        counters.put(times, 1);\r\n    else\r\n        counters.put(times, count + 1);\r\n}\r\n<\/pre>\n<p>This creates objects for each task. While it is common practice to use int for loop counters its is also common practice to use <i>Iterator<\/i> You can play around with the types and parameters of this micro-benchmark, however you get a memory profile which will be familiar to many developers who have tried to tune their application. Using VisualVM the heap usage looks like this over a five minute period.<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/3.bp.blogspot.com\/-RLfWaJojJMo\/ThK7dqHE3iI\/AAAAAAAAADU\/ZhY_ido-ohE\/s1600\/wrapper-main-heap.png\"><img decoding=\"async\" border=\"0\" height=\"324\" src=\"http:\/\/3.bp.blogspot.com\/-RLfWaJojJMo\/ThK7dqHE3iI\/AAAAAAAAADU\/ZhY_ido-ohE\/s640\/wrapper-main-heap.png\" width=\"640\" \/><\/a><\/div>\n<p>There was 20 minor GCs in about 6 minutes.<br \/>\nThe average time of each loop is sub-microsecond which is pretty fast.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Took 4,099 ns per loop<br \/>\nTook 559 ns per loop<br \/>\nTook 115 ns per loop<br \/>\nTook 240 ns per loop<br \/>\nTook 255 ns per loop<br \/>\nIn the first test, the JVM hasn&#8217;t warmed up.<\/p>\n<p>Can using primitives really make much difference?<\/p>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Performance of using primitives<\/span><\/strong><br \/>\nThe following benchmark behaves rather differently to most applications. Even though it is doing the same work as the previous benchmark, there is no objects created.<\/p>\n<p><i>Loop using Primitives and array<\/i><\/p>\n<pre class=\"brush:java\">int[] counters = new int[144];\r\nint runs = 20 * 1000;\r\nfor (int i = 0; i &lt; runs; i++) {\r\n    int x = i % 12;\r\n    int y = i \/ 12 % 12;\r\n    int times = x * y;\r\n    counters[times]++;\r\n}\r\n<\/pre>\n<p>and the heap usage reflects this <\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/4.bp.blogspot.com\/-r4EkaLTlH_4\/ThK8l_GI7CI\/AAAAAAAAADc\/ZwiSsQRnLxo\/s1600\/primitive-main-heap.png\"><img decoding=\"async\" border=\"0\" height=\"328\" src=\"http:\/\/4.bp.blogspot.com\/-r4EkaLTlH_4\/ThK8l_GI7CI\/AAAAAAAAADc\/ZwiSsQRnLxo\/s640\/primitive-main-heap.png\" width=\"640\" \/><\/a><\/div>\n<p>There was no GCs over a period of 5 minutes. The test could have run longer and still not triggered a GC.<br \/>\nAnd the average time per loop is much lower as well<\/p>\n<p>Took 198 ns per loop<br \/>\nTook 17 ns per loop<br \/>\nTook 16 ns per loop<br \/>\nTook 14 ns per loop<br \/>\nTook 15 ns per loop<\/p>\n<p>In the first test, the JVM hasn&#8217;t warmed up.<\/p>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Conclusion<\/span><\/strong><br \/>\nUsing primitives will perform better. (Unless there is excessive boxing and unboxing)<\/p>\n<p>Even in applications where performance is not critical, it will improve clarity, both of the code and when you do attempt to profile your application, it will reduce the level of &#8220;noise&#8221; making it clearer as to what the problem is.<\/p>\n<p><span class=\"Apple-style-span\" style=\"font-size: large\"><strong>Notes<\/strong><\/span><br \/>\nEven in the test where few objects were created, you can see some object allocation. This is mostly due to VisualVM&#8217;s polling. To reduce this I changed the polling interval from 3 seconds to 20 seconds.<\/p>\n<p>The Eden size was increased to make the graphs clearer with <i>-XX:NewSize=100m<\/i> This value is not recommend (except perhaps for micro-benchmarks) but its is a parameter you may need to tune for your application.<\/p>\n<p><span class=\"Apple-style-span\" style=\"font-size: large\"><strong>Full code<\/strong><\/span><\/p>\n<ul>\n<li><a href=\"http:\/\/code.google.com\/p\/core-java-performance-examples\/source\/browse\/trunk\/src\/main\/java\/com\/google\/code\/java\/core\/primitives\/PrimitiveMain.java\">Primitive benchmark<\/a><\/li>\n<li><a href=\"http:\/\/code.google.com\/p\/core-java-performance-examples\/source\/browse\/trunk\/src\/main\/java\/com\/google\/code\/java\/core\/primitives\/WrapperMain.java\">Wrapper benchmark<\/a><\/li>\n<\/ul>\n<div><strong><i><br \/>\n<\/i><\/strong><br \/>\n<strong><i>Reference:&nbsp;<\/i><\/strong><a href=\"http:\/\/vanillajava.blogspot.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html\">Low GC in Java: Use primitives instead of wrappers<\/a>&nbsp;from our&nbsp;<a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a>&nbsp;<a href=\"http:\/\/www.blogger.com\/profile\/17982030676088168612\">Peter Lawrey<\/a>&nbsp;at the&nbsp;<a href=\"http:\/\/vanillajava.blogspot.com\/\">Vanilla Java<\/a>.<\/p>\n<div style=\"margin-bottom: 0px;margin-left: 0px;margin-right: 0px;margin-top: 0px\"><strong>Related Articles:<\/strong><\/div>\n<ul style=\"text-align: left\">\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/12\/things-every-programmer-should-know.html\">Things Every Programmer Should Know<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/01\/10-tips-proper-application-logging.html\">10 Tips for Proper Application Logging<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/01\/laws-of-software-design.html\">Laws of Software Design<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/?tag=java-best-practices\">Java Best Practices Series<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/02\/9-tips-on-surviving-wild-west.html\">9 Tips on Surviving the Wild West Development Process<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/02\/9-tips-on-surviving-wild-west.html\"><\/a><a href=\"http:\/\/www.javacodegeeks.com\/2010\/12\/how-to-do-100k-tps-at-less-than-1ms.html\">How to Do 100K TPS at Less than 1ms Latency<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/12\/how-to-do-100k-tps-at-less-than-1ms.html\"><\/a><a href=\"http:\/\/www.javacodegeeks.com\/2010\/12\/revving-up-your-hibernate-engine.html\">Revving Up Your Hibernate Engine<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview There are two good reason to use primitives instead of wrappers where possible. Clarity. By using a primitive, you are making it clear that a null value is not appropriate. Performance. Using primitives is often much faster. Clarity is often more important than performance, and is the best reason to use them. However, this &hellip;<\/p>\n","protected":false},"author":44,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[66,137,121],"class_list":["post-478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-java-best-practices","tag-performance","tag-performance-and-scalability"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Low GC in Java: Use primitives instead of wrappers - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Overview There are two good reason to use primitives instead of wrappers where possible. Clarity. By using a primitive, you are making it clear that a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Low GC in Java: Use primitives instead of wrappers - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Overview There are two good reason to use primitives instead of wrappers where possible. Clarity. By using a primitive, you are making it clear that a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-08T22:33:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:01:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Peter Lawrey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Peter Lawrey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html\"},\"author\":{\"name\":\"Peter Lawrey\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/8da43fffe34a1882e1402265732ec89e\"},\"headline\":\"Low GC in Java: Use primitives instead of wrappers\",\"datePublished\":\"2011-07-08T22:33:00+00:00\",\"dateModified\":\"2012-10-21T20:01:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html\"},\"wordCount\":561,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"Java Best Practices\",\"Performance\",\"Performance and Scalability\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html\",\"name\":\"Low GC in Java: Use primitives instead of wrappers - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2011-07-08T22:33:00+00:00\",\"dateModified\":\"2012-10-21T20:01:23+00:00\",\"description\":\"Overview There are two good reason to use primitives instead of wrappers where possible. Clarity. By using a primitive, you are making it clear that a\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/low-gc-in-java-use-primitives-instead.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Low GC in Java: Use primitives instead of wrappers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/8da43fffe34a1882e1402265732ec89e\",\"name\":\"Peter Lawrey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cbaad37aad868f26df8922ff947ff9f4311a7c2bf5c67f952728a35a330c4e66?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cbaad37aad868f26df8922ff947ff9f4311a7c2bf5c67f952728a35a330c4e66?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cbaad37aad868f26df8922ff947ff9f4311a7c2bf5c67f952728a35a330c4e66?s=96&d=mm&r=g\",\"caption\":\"Peter Lawrey\"},\"sameAs\":[\"http:\\\/\\\/vanillajava.blogspot.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Peter-Lawrey\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Low GC in Java: Use primitives instead of wrappers - Java Code Geeks","description":"Overview There are two good reason to use primitives instead of wrappers where possible. Clarity. By using a primitive, you are making it clear that a","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:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html","og_locale":"en_US","og_type":"article","og_title":"Low GC in Java: Use primitives instead of wrappers - Java Code Geeks","og_description":"Overview There are two good reason to use primitives instead of wrappers where possible. Clarity. By using a primitive, you are making it clear that a","og_url":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-07-08T22:33:00+00:00","article_modified_time":"2012-10-21T20:01:23+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Peter Lawrey","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Peter Lawrey","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html"},"author":{"name":"Peter Lawrey","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/8da43fffe34a1882e1402265732ec89e"},"headline":"Low GC in Java: Use primitives instead of wrappers","datePublished":"2011-07-08T22:33:00+00:00","dateModified":"2012-10-21T20:01:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html"},"wordCount":561,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["Java Best Practices","Performance","Performance and Scalability"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html","url":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html","name":"Low GC in Java: Use primitives instead of wrappers - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2011-07-08T22:33:00+00:00","dateModified":"2012-10-21T20:01:23+00:00","description":"Overview There are two good reason to use primitives instead of wrappers where possible. Clarity. By using a primitive, you are making it clear that a","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/low-gc-in-java-use-primitives-instead.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Low GC in Java: Use primitives instead of wrappers"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/8da43fffe34a1882e1402265732ec89e","name":"Peter Lawrey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cbaad37aad868f26df8922ff947ff9f4311a7c2bf5c67f952728a35a330c4e66?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cbaad37aad868f26df8922ff947ff9f4311a7c2bf5c67f952728a35a330c4e66?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cbaad37aad868f26df8922ff947ff9f4311a7c2bf5c67f952728a35a330c4e66?s=96&d=mm&r=g","caption":"Peter Lawrey"},"sameAs":["http:\/\/vanillajava.blogspot.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Peter-Lawrey"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}