-
Notifications
You must be signed in to change notification settings - Fork 1.3k
KVO blocks API causing KVO crashes on object dealloc #200
Comments
If it is as written, |
I'm actually using
But why do you say it's a leak? |
Then in that case it's not a leak, heh heh. |
What are you deploying to? 5, 6, or 7? Going to try and reproduce. |
7 |
Thanks for having a look into it! I tried to point my Podfile to the
I remember reading about this before. So I temporarily removed this flag, and now I get more serious link errors:
|
Even if I couldn't use it for my project, I downloaded BlocksKit with your latest commit and managed to write a failing test:
To make 100% clear that adding the observer is what keeps the object alive, here is a passing test:
If I understand the way the block methods were implemented, the observers are added to a |
Ok, perhaps I'm going crazy, but I could have sworn that the UPDATE: I saw that it changed on last commit. Still trying to understand this. |
Ok I think I get it now. Please correct me if I'm wrong: you now swizzle a new dealloc method on all observed objects. The swizzled dealloc method removes all observers. But as the |
I changed the
I then placed a breakpoint in the swizzled dealloc block-method. It gets called all right, but the issue seems to be coming from |
Ah, I see. The map table implementation hasn't been really used before (due to the 5.0 deployment target). The way we store the observers currently is poorly suited for map tables, as the apparently weak keys get purged at some point before dealloc. When we drop iOS 5 (soon), we'll reformat the observer extensions for it. Currently working on fixing the |
Is there something I can do to use the observer APIs meanwhile without any memory leaks/crashes? Disable the map tables implementation? I'm sorry to bother you again, but I'm in a rush to finish a client project and I've been using these APIs everywhere ^^ |
Apologies! Using he current "master", just change HAS_MAP_TABLE to 0. |
Saw the changes you made in |
These changes on |
Is it me or has all BlocksKit code disappeared from |
First of all, thanks so much for BlocksKit. It's a real time saver!
Now the problem: I've started using the KVO APIs (
bk_addObserverForKeyPath:task:
) and I'm getting some crashes when my objects are being dealloced:I've spent some time trying to debug this. I'm fairly sure I got rid of all memory issues caused by reference cycles in blocks by doing the weakSelf/strongSelf dance. But this one is strange. The only observers on the objects in question are created by the objects themselves:
Any ideas?
The text was updated successfully, but these errors were encountered: