What is the difference Memory Leak and a Zombie?
Asked Answered
H

2

18

I am working on a ARC based project . I have never worked on Non ARC based project .Recently I

came across a zombie in my ARC enabled project.As far as I understood there wont be memory

leaks in ARC , as the objects will be deallocated automatically.But I came across a zombie

saying "message passed to a deallocated instance".My confusion is is a Memory Leak equivalent

to a Zombie. If that is the case then Memory Leak occur in ARC too ? Any help ?

Haslet answered 1/10, 2012 at 4:46 Comment(4)
it's not ARC's fault. say you have some weak pointer and it's deallocated, then you see that.Isolative
@iBlue: a proper weak pointer under ARC would become nil when the object is deallocated, but the underlying point that "message passed to a deallocated instance" is caused by holding a pointer to an object that has been deallocated is correct.Brumley
@Brumley yea I'm saying if after it's deallocated you try to do something to it, then you will see that, and it's not ARC's fault.Isolative
This May Help you : #8276305, #10805365Teredo
T
43

"Zombies" in Objective-C parlance are the opposite of leaks. A leak is a bit of allocated memory that you no longer have any references to, so you can't free it. A zombie is an object that has been deallocated, but references to it still exist and messages are still being sent to it (which can lead to all sorts of unpredictable behavior).

Taam answered 1/10, 2012 at 4:53 Comment(4)
he "chuck"ed the confusion :pArrowroot
@guru They're very closely related — zombies are a way of identifying dangling pointers to objects.Taam
Can this still happen in Swift? I mean if you send a message to a deallocated object then all you'll get is fatalError for (forcefully) unwrapping a nil object right? I assume in the case of safe access you won't have an issue...But if I'm wrong and it can happen in Swift, then can you just share a sample code to recreate a zombie object, because while I've created memory cycles, I don't think I've never been able to create a zombie objectWo
For an answer to my previous comment see: How can I demonstrate a zombie leak for Swift?Wo
B
1

There are several possibilities and it's hard to know what's going on without seeing code. The "message passed to a deallocated instance" error means that you have a pointer that points to where an object had been, but has since been deallocated. This can and does still happen with ARC. It can happen because you have some non-ARC code (or perhaps Core Foundation stuff) interacting with ARC code and things are going awry at the hand-offs. It can also happen because while ARC picks the correct points in time to release objects nearly every single time, it's not perfect (usually there are ways to work around these instances).

Brumley answered 1/10, 2012 at 4:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.