What is the difference Memory Leak and a Zombie?

2019-02-04 12:17发布

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 ?

2条回答
虎瘦雄心在
2楼-- · 2019-02-04 12:25

"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).

查看更多
萌系小妹纸
3楼-- · 2019-02-04 12:31

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).

查看更多
登录 后发表回答