{"id":231,"date":"2013-04-06T21:59:29","date_gmt":"2013-04-06T21:59:29","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=231"},"modified":"2013-08-08T11:12:09","modified_gmt":"2013-08-08T11:12:09","slug":"dispose-pattern","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/dispose-pattern\/","title":{"rendered":"Dispose pattern"},"content":{"rendered":"<p>A quick post to show the implementation of the Dispose pattern for IDisposable implementations.<\/p>\n<p><em>Note: this is not threadsafe<\/em><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic class MyObject : IDisposable\r\n{\r\n   protected bool disposed;\r\n\r\n   \/\/ only required if we need to release unmanaged resources\r\n   ~MyObject()\r\n   {\r\n      Dispose(false);\r\n   }\r\n\r\n   public void Dispose()\r\n   {\r\n      Dispose(true);\r\n      GC.SuppressFinalize(this);\r\n   }\r\n\r\n   protected virtual void Dispose(bool disposing)\r\n   {\r\n      if(!disposed)\r\n      {\r\n         if(disposing)\r\n         {\r\n            \/\/ dispose of any managed resources here\r\n         }\r\n         \/\/ clean up any unmanaged resources here\r\n      }\r\n      disposed = true;\r\n   }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A quick post to show the implementation of the Dispose pattern for IDisposable implementations. Note: this is not threadsafe public class MyObject : IDisposable { protected bool disposed; \/\/ only required if we need to release unmanaged resources ~MyObject() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,2],"tags":[],"class_list":["post-231","post","type-post","status-publish","format-standard","hentry","category-c","category-programming"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":8,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":706,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/231\/revisions\/706"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}