{"id":113,"date":"2014-09-22T12:41:44","date_gmt":"2014-09-22T10:41:44","guid":{"rendered":"http:\/\/blog.calj.net\/en\/?p=113"},"modified":"2014-09-22T12:41:44","modified_gmt":"2014-09-22T10:41:44","slug":"correctly-handling-dealloc-on-arm64","status":"publish","type":"post","link":"https:\/\/blog.calj.net\/en\/correctly-handling-dealloc-on-arm64\/","title":{"rendered":"Correctly handling dealloc on arm64"},"content":{"rendered":"<div style=\"text-align: right;\"><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fblog.calj.net%2Fen&#038;t=Correctly%20handling%20dealloc%20on%20arm64&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fblog.calj.net%2Fen&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Fblog.calj.net%2Fen%2Fwp-content%2Fuploads%2F2014%2F09%2FApple-honey.jpg&#038;p&#091;title&#093;=Correctly%20handling%20dealloc%20on%20arm64\" style=\"font-size: 0px;width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline;width:16px;height:16px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/blog.calj.net\/en\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?text=Correctly%20handling%20dealloc%20on%20arm64&#038;url=https%3A%2F%2Fblog.calj.net%2Fen&#038;via=calj_net\" style=\"font-size: 0px;width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline;width:16px;height:16px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/blog.calj.net\/en\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fblog.calj.net%2Fen&#038;title=Correctly%20handling%20dealloc%20on%20arm64\" style=\"font-size: 0px;width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline;width:16px;height:16px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/blog.calj.net\/en\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Correctly%20handling%20dealloc%20on%20arm64&#038;body=Hey%20check%20this%20out:%20https%3A%2F%2Fblog.calj.net%2Fen\" style=\"font-size: 0px;width:16px;height:16px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline;width:16px;height:16px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/blog.calj.net\/en\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/mail.png\" \/><\/a><\/div><p>I want to share some feedback following my <a title=\"CalJ v2.6.1 crashes on iPhone 5S\" href=\"http:\/\/blog.calj.net\/en\/calj-v2-6-crashes-on-iphone-5s\/\" target=\"_blank\">latest bug<\/a>: an unexplained crash which no <a href=\"http:\/\/juliusparishy.com\/symbolicating-ios-8-crash-logs\/\" target=\"_blank\">symbolication<\/a> could help resolve.<\/p>\n<p>Given the following property of my City object:<\/p>\n<p>in City.h<\/p>\n<pre style=\"padding-left: 30px;\"><span style=\"color: #ff00ff;\">@property<\/span> (<span style=\"color: #ff00ff;\">nonatomic<\/span>, <span style=\"color: #ff00ff;\">retain<\/span>) <span style=\"color: #800080;\">NSString<\/span> * name;<\/pre>\n<p>The destructor looked like this in City.m<\/p>\n<pre style=\"padding-left: 30px;\">- (<span style=\"color: #ff00ff;\">void<\/span>) dealloc\r\n{\r\n\u00a0 [<span style=\"color: #ff00ff;\">super<\/span> <span style=\"color: #800080;\">dealloc<\/span>];\r\n\u00a0 [<span style=\"color: #008080;\">name <\/span><span style=\"color: #800080;\">release<\/span>];\r\n}\r\n<\/pre>\n<p>This code had worked perfectly fine on every iOS platform for years, until I compiled for the first time for t the arm64 architecture. Then it stopped to work, with an EXC_BAD_ACCESS (SIGSEGV) of subtype: KERN_INVALID_ADDRESS.<\/p>\n<p>Not having, initially, an iPhone 5s at hand to find where the problem was exactly, I could only rely on the crashlogs and the symbolication for arm64. Unforunately, they would not indicate anything useful.<\/p>\n<pre style=\"padding-left: 30px;\">(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 520\r\n_CFAutoreleasePoolPop + 24\r\n-[NSAutoreleasePool release] + 148<\/pre>\n<p>Well, it did talk about some release pool problem, but could never pinpoint the above section of code.<\/p>\n<p>It was not until I was able to use a friend&#8217;s iPhone 5s terminal, that I finally realized that the destructor should actually read like this:<\/p>\n<pre style=\"padding-left: 30px;\">- (<span style=\"color: #ff00ff;\">void<\/span>) dealloc\r\n{\r\n\u00a0 [<span style=\"color: #008080;\">name <\/span><span style=\"color: #800080;\">release<\/span>];\r\n\u00a0 <span style=\"color: #008080;\">name<\/span> = <span style=\"color: #ff00ff;\">nil<\/span>;\r\n\u00a0 [<span style=\"color: #ff00ff;\">super<\/span> <span style=\"color: #800080;\">dealloc<\/span>];\r\n}<\/pre>\n<p>Calling the super prior to releasing and erase the name pointer would cause a crash on\u00a0the A7 chip in a 64-bit slice.<br \/>\nOf course, you\u00a0surely have been using ARC for a long time already, and won&#8217;t care too much about this old-stlye kind of problems. But I am not fond of managed memory, no matter the platform. I will continue to use manual memory allocation\/de- as long as the language offers to do so.<\/p>\n<p>Oh, and, if anyone is interested in the arm64 debug symbols for Xcode, I keep them at hand for download. Just ask me with the form below. Apple won&#8217;t like it, but I don&#8217;t like them either, so we&#8217;re even.<\/p>\n<p>Many thanks to <a href=\"https:\/\/twitter.com\/dsultan\" target=\"_blank\">@dsultan<\/a>\u00a0for his precious help &amp; time.<\/p>\n<h5>\u00a0! Shana Tova \u05e9\u05e0\u05d4 \u05d8\u05d5\u05d1\u05d4 !<\/h5>\n<p style=\"padding-left: 60px;\">Gabriel<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to share some feedback following my latest bug: an unexplained crash which no symbolication could help resolve. Given&hellip;<\/p>\n","protected":false},"author":1,"featured_media":121,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[22,17,15,23,21,14,20,19,24],"class_list":["post-113","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","tag-arm64","tag-bug","tag-crash","tag-debug","tag-developer","tag-iphone","tag-memory","tag-objective-c","tag-xcode"],"_links":{"self":[{"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":8,"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/posts\/113\/revisions\/122"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/media\/121"}],"wp:attachment":[{"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.calj.net\/en\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}