facebookarchive / FBAllocationTracker

iOS library that helps tracking all allocated Objective-C objects
Other
1.09k stars 139 forks source link

Switches tracking from +alloc to +allocWithZone: #36

Closed grigorye closed 5 years ago

grigorye commented 5 years ago

This is iteration on #29 after fixing #35.

It turns out that +alloc is not used at least for some objects loaded from .storyboards (nibs?), but +allocWithZone: is used instead. Particularly, in my case I saw it like deallocations tracked for navigation controllers (when they're disposed), without tracking allocations, hence the (live) count of navigation controllers in currentAllocationSummary eventually decreased below zero.

You can easily check it yourself with storyboards, I've added unit test illustrating the problem as well.

Overall I believe it makes sense to patch +allocWithZone: instead of +alloc just because it's kind of historical thing (and was used freely in "old" source bases) - otherwise you had a great chance to miss it like in this case with storyboards.