{"id":6498,"date":"2014-04-19T04:41:20","date_gmt":"2014-04-19T04:41:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/19\/c-large-byte-array-and-memory-leak-if-not-nulled-quickly-collection-of-common-programming-errors\/"},"modified":"2014-04-19T04:41:20","modified_gmt":"2014-04-19T04:41:20","slug":"c-large-byte-array-and-memory-leak-if-not-nulled-quickly-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/19\/c-large-byte-array-and-memory-leak-if-not-nulled-quickly-collection-of-common-programming-errors\/","title":{"rendered":"C# large byte array and memory leak if not nulled quickly-Collection of common programming errors"},"content":{"rendered":"<p>Your findings are not unusual, but it doesn&#8217;t mean that anything is wrong either. In order to be collected, something must prompt the GC to collect (often an attempted allocation). As a result, you can build an app that consumes a bunch of memory, releases it, and then goes idle. If there is no memory pressure on the machine, and if your app doesn&#8217;t try to do anything after that, the GC won&#8217;t fire (because it doesn&#8217;t need to). Once you get busy, the GC will kick in and do its job. This behavior is very commonly mistaken for a leak.<\/p>\n<p>BTW: Are you using that very large array more than once? If so, you might be better off keeping it around and reusing it. Reason: any object larger than 85,000 bytes is allocated on the Large Object Heap. That heap only gets GC&#8217;d on Generation 2 collections. So if you are allocating and reallocating arrays very often, you will be causing a lot of Gen 2 (expensive) collections.<\/p>\n<p>(note: that doesn&#8217;t mean that there&#8217;s a hard and fast rule to always reuse large arrays, but if you are doing a lot of allocation\/deallocation\/allocation of the array, you should measure how much it helps if you re-use).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Your findings are not unusual, but it doesn&#8217;t mean that anything is wrong either. In order to be collected, something must prompt the GC to collect (often an attempted allocation). As a result, you can build an app that consumes a bunch of memory, releases it, and then goes idle. If there is no memory [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6498","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6498"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6498\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}