{"id":3993,"date":"2014-03-30T07:00:52","date_gmt":"2014-03-30T07:00:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/detect-windowhandle-leaks-in-a-c-application-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:00:52","modified_gmt":"2014-03-30T07:00:52","slug":"detect-windowhandle-leaks-in-a-c-application-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/detect-windowhandle-leaks-in-a-c-application-collection-of-common-programming-errors\/","title":{"rendered":"Detect windowhandle leaks in a c# application-Collection of common programming errors"},"content":{"rendered":"<p>Any decent memory profiler will show you the control instances. They won&#8217;t be garbage collected, their Handle property keeps them alive. There will be close to 10,000 of them.<\/p>\n<p>A code review ought to go a long way too, there are not that many possible ways to leak a window. Look for code that calls Controls.Remove() but don&#8217;t explicitly dispose the control. Or a form displayed with ShowDialog() that doesn&#8217;t get disposed <em>and<\/em> forgets to unregister a static event handler (SystemEvents e.g.)<\/p>\n<p>Finding the handles yourself at runtime is technically possible with Reflection. The handles are stored in System.Internal.HandleCollector.handleTypes[]. Well, technically.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Any decent memory profiler will show you the control instances. They won&#8217;t be garbage collected, their Handle property keeps them alive. There will be close to 10,000 of them. A code review ought to go a long way too, there are not that many possible ways to leak a window. Look for code that calls [&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-3993","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3993","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=3993"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3993\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}