{"id":77,"date":"2008-07-05T20:06:27","date_gmt":"2008-07-06T01:06:27","guid":{"rendered":"http:\/\/vgable.com\/blog\/2008\/07\/05\/dealloc-warning\/"},"modified":"2008-07-05T20:06:29","modified_gmt":"2008-07-06T01:06:29","slug":"dealloc-warning","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2008\/07\/05\/dealloc-warning\/","title":{"rendered":"-dealloc Warning"},"content":{"rendered":"<p>The <strong>only<\/strong> time you should call ever call <code><a href=\"http:\/\/developer.apple.com\/documentation\/Cocoa\/Reference\/Foundation\/Classes\/NSObject_Class\/Reference\/Reference.html#\/\/apple_ref\/occ\/instm\/NSObject\/dealloc\">-dealloc<\/a><\/code> in Objective-C is on the last line of your own <code>-dealloc<\/code> method.  This call should be <code>[super dealloc];<\/code>.  The proper way to dispose of an object is to send it a <code>-release<\/code> message &#8212; <code>-dealloc<\/code> will then be called <em>if appropriate<\/em>.<\/p>\n<p>Now when I was first learning Cocoa, I sometimes disposed of objects by calling <code>-dealloc<\/code> directly.  This caused all sorts of problems.     Truth be known, if I&#8217;ve been messing with several object&#8217;s <code>-dealloc<\/code> methods, I&#8217;ll sometimes dyslex out and type <code>dealloc<\/code> when I mean <code>release<\/code>, just because it&#8217;s more fresh in my head.  This is very rare, but it has happened once, and will happen again.  I&#8217;m fallible like that.  Murphy&#8217;s law tells us that I won&#8217;t catch it every time.<\/p>\n<p>So I humbly propose that <strong>GCC should warn you if you use <code>-dealloc<\/code> any way other then calling <code>[super dealloc];<\/code> on the last line of your own <code>-dealloc<\/code> methods<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The only time you should call ever call -dealloc in Objective-C is on the last line of your own -dealloc method. This call should be [super dealloc];. The proper way to dispose of an object is to send it a -release message &#8212; -dealloc will then be called if appropriate. Now when I was first [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,6,3,5,4],"tags":[76],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-bug-bite","category-cocoa","category-macosx","category-objective-c","category-programming","tag-gcc"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}