This is because if memory usage gets too high, the OS will send a kill signal to the process, which can be neither detected nor caught.
This means that in our original decision to use this fix, all we had was anecdotal evidence of untraceable crashes. Luckily we had dedicated QA that was keeping pretty solid track of them all, and they piled up.
In our case I think it was worth it.
You'd be surprised what can be detected and caught.
Another commenter recommended touching a file at launch and at sleep to track untraceable crashes, which we do for various other reasons, but don't upload the stats. We may begin doing this.
if ([self.data retainCount] != [self.data retainCount]) {
[[[self.data release] release] release];
}
Written from memory, so excuse any mistakes. First (and only) time I've ever seen a legitimate use for `retainCount`. @bbum would be proud (or perhaps horrified).That's super weird - I have yet to encounter something along these lines in my Cocoa work so far. Solid idea to beat the system there. I just hope it's got a nice comment above it haha.
I would imagine this is what leads to the 0.4% crash rate I mentioned at the top of the article :-(
This may be nitpicking, but it made it hard for me to pay attention to the real meat of the thing.
Doesn't it make sense to say that without the existence of Apple GC, the bug never would have existed? Doesn't that at least somewhat justify the title?
edit: Furthermore the original intent of including garbage collection in the title was as an ironic twist based on the fact that ios has never had garbage collection. Maybe that didn't convey as well as I would have liked.
Without GC, this code would have been written as simply:
CFRetain(data);
And the same bug would manifest. The bug is just a missing release call.Edit: I'd assume they were going for the standard pattern for code that needs to be both GC and non-GC for bridging CF objects out into the Cocoa world:
[NSMakeCollectable(cfobj) autorelease];
In this case, "obj" was retained inline. They just forgot the autorelease. They could have forgotten it just as easily without garbage collection, and the NSMakeCollectable (which inlines to CFMakeCollectable) call is unrelated, aside from possibly occupying the wrong spot of the original programmer's brain at the wrong moment.