We know that when object retain counts reaches to 0 then it turns into Zombie object. What happens if we access that object?
-
only if you have zombies enabled will it turn into a zombie – Daij-Djan Dec 17 '14 at 12:51
2 Answers
If Zombies are enabled then the object will not be freed when all references to it are removed; instead a log message will be generated to help you track down where this invalid reference is coming from.

- 9,691
- 1
- 20
- 27
-
Thanks for your answer. I will check the log message. What if set that object to nil? Will Zombie object still be there in memory. – Shashi3456643 Dec 17 '14 at 12:14
-
References are never set to point to Zombie object if you do not have Zombies turned on. Then the reference continue to point to the freed object. A common issue if you are using ARC is a "weak" property that gets accessed after the object it points to are already freed. – Peter Segerblom Dec 17 '14 at 12:50
-
-
@PeterSegerblom don't get it ;) and i daresay it isn't correct here... the point is nszombies arent freed - arc or not – Daij-Djan Dec 17 '14 at 12:53
-
@Daij-Djan exactly, NSZombies are a "debug tool" used to track down dangling pointers. Nothing is set to NSZombies in production code, then the pointer just points to a memory location already released back to the system. or am i wrong about that? – Peter Segerblom Dec 17 '14 at 14:31
-
####
** Message sent to deallocated instance 0xFFFFFFF **
####
While the original answer was crash or undefined behavior, this is completely true for non-debug builds, not when you debug your app, as it requires certain flag to be used to activate NSZombies.
Actually there is no such thing as zombie per se.
Memory that holds your object isn't zeroed upon release. This memory simply marked as free by memory manager and can be reused later, and be completely or partially overwritten by some other object or data.
So if you access dead objects without NSZombies turned on, you can imagine, you get crash or undefined behavior, it even may work for a while.
NSZombies debugging technique helps to track that by replacing released memory with some sort of Zombie objects that log message when you access them (which normally should not happen).
p.s: HATERS GONNA HATE

- 12,068
- 5
- 54
- 82
-
no. a nszombie isn't undefined, quite the opposite. it just won't be freed. accessing a nszombie is fine – Daij-Djan Dec 17 '14 at 12:52
-
OK yep agree, with NSZombie it's exception. But certainly for objects to turn into zombies, you have to set up the debug flag. – pronebird Dec 17 '14 at 12:53
-
-