<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2014-11-07-lets-build-nszombie.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 10 May 2026 05:03:41 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>bob - 2014-12-04 09:06:23</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>I wonder if it would be useful to create a zombie that doesn't prevent deallocation -- it would still catch incorrect message sends for a while, up until the memory gets overwritten. And since it doesn't leak, it can be used in production. What do you think?</description><guid isPermaLink="true">b18291cd03404d1f5caf43aa6e0b529b</guid><pubDate>Thu, 04 Dec 2014 09:06:23 GMT</pubDate></item><item><title>Connor Sadler - 2014-11-11 11:29:03</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>I enjoyed the tags ;]</description><guid isPermaLink="true">c909adcc46b0326b4e4befe6f764ea35</guid><pubDate>Tue, 11 Nov 2014 11:29:03 GMT</pubDate></item><item><title>Brent Royal-Gordon - 2014-11-09 21:10:23</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>Rather than dynamically installing +initialize and -methodSignatureForSelector:, couldn't you just write an MAZombie base class and have all of your individual zombie classes subclass it? It seems like that would reduce the amount of runtime magic you need to write for each zombie class.
&lt;br /&gt;
&lt;br /&gt;Also, I believe this implementation of zombies won't call -.cxx_destruct, which is used by ARC. Would it be a good idea to call that in ZombieDealloc?</description><guid isPermaLink="true">826d90bcfb02e8ce8fa8ac285806291b</guid><pubDate>Sun, 09 Nov 2014 21:10:23 GMT</pubDate></item><item><title>mikeash - 2014-11-08 02:29:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>&lt;b&gt;Rick:&lt;/b&gt; The CF stuff is a big problem, and one that NSZombie actually shared for many years. The requirement to call super is related, and I don't think NSZombie will catch that either. Once you start doing custom allocators it's hard to hook stuff reliably. You could swizzle dealloc, but how will you stop the memory from being deallocated? You still need to run the rest of the dealloc code for things to work properly. And you're right, I originally meant to get this article out last week but didn't quite make it!
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Konstantin Anoshkin:&lt;/b&gt; You're right, we could safely assume there's enough storage for another pointer in the real world. But I didn't like to make that assumption, partly just because it's messy, and partly because there's nothing that says Apple couldn't decide to use a more fine-grained allocator for objects that don't have any extra ivars. In a real implementation, assuming you're only running it for debugging and you check with malloc_size before you start overwriting stuff, it would be fine.</description><guid isPermaLink="true">aa324e1df69652dfb5c068d552adcc17</guid><pubDate>Sat, 08 Nov 2014 02:29:53 GMT</pubDate></item><item><title>Konstantin Anoshkin  - 2014-11-07 20:52:42</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>"If the original class had no additional instance variables, then there's no space that can be repurposed for storage."
&lt;br /&gt;
&lt;br /&gt;Technically speaking, the granularity of malloc() on Darwin is 16 bytes, which is a minimum space occupied by an Obj-C object (barring evil custom +alloc implementations, of course). The isa variable on a 64-bit system occupies 8 bytes, which still leaves 8 bytes for a pointer to the original class. In other words, that's a great opportunity for optimization for 99.9% cases on all currently supported Apple systems. Just my 2 cents.</description><guid isPermaLink="true">e35566a1c69a899c20047dd6deec4731</guid><pubDate>Fri, 07 Nov 2014 20:52:42 GMT</pubDate></item><item><title>Avi Drissman - 2014-11-07 17:40:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>If you want to see a different implementation of zombies, including a treadmill, one that has been hardened by shipping it for years, check out the Chromium version:
&lt;br /&gt;
&lt;br /&gt;&lt;a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/mac/objc_zombie.mm"&gt;https://chromium.googlesource.com/chromium/src/+/master/chrome/common/mac/objc_zombie.mm&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;Disclosure: I'm on the Chrome team, though I never worked on the zombie implementation.</description><guid isPermaLink="true">41a2febac1ae598a74e570608afb6151</guid><pubDate>Fri, 07 Nov 2014 17:40:53 GMT</pubDate></item><item><title>Rick - 2014-11-07 17:31:27</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2014-11-07-lets-build-nszombie.html#comments</link><description>Cool. Sounds like there's a couple of weak points, though: 1. The CF bridging weirdness you mentioned. 2. Zombify requires a class' dealloc implementation to call super. Could one swizzle dealloc instead? You'd need a place to catch the loading/registering of every class to swizzle its dealloc, though. 
&lt;br /&gt;
&lt;br /&gt;Also, this article is a week late. October is for zombies... Now we need articles on NSTurkey. Or NSPumpkinSpiceLatte, or something... :)</description><guid isPermaLink="true">9a4fba5b03c379ab0afd38f36b65e6c1</guid><pubDate>Fri, 07 Nov 2014 17:31:27 GMT</pubDate></item></channel></rss>
