> On Jul 15, 2016, at 10:13, Christiaan Hofman <cmhof...@gmail.com> wrote: > > Interesting, this does seem to be involved. I tried implementing these two > methods (well, that should be_tryRetain instead of _tryRelease), and didn’t > see the crasher anymore. > > I implemented these as follows. First, change the rc by steps of 2 instead of > 1 (and bit-shift back in retainCount). When deallocating (why does spell > check want defecating?), set the rc to 1 to flag it as deallocating. In > _tryRetain, return NO when this flag is set, otherwise increment (by 2) and > return YES. As for _isDeallocating, return the “1” bit flag.
Well I’ll be. Nice job of finding that! Apparently NSObject is in the runtime now, and open source. https://opensource.apple.com/source/objc4/objc4-680/runtime/NSObject.mm > > So it does seem to be the case that objc messes with memory management behind > our backs, using undocumented methods. Very bad behavior. I think weak > references use _tryRetain, then thinks it retained, but in fact didn’t, > because it wasn’t using our rc ivar but rather the unused default mechanism. > So the retain count is now one lower than it should be. I wonder if it’s NSNotificationCenter doing something wrong vs. objc itself. I’ve not been reading release notes for the last couple of releases, so missed this: https://developer.apple.com/library/mac/releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_11.html#//apple_ref/doc/uid/TP40016227-SW1 "NSNotificationCenter and NSDistributedNotificationCenter no longer send notifications to registered observers that may be deallocated. If the observer is able to be stored as a zeroing-weak reference the underlying storage stores the observer as a zeroing weak reference. Alternatively, if the object cannot be stored weakly (because it has a custom retain/release mechanism that would prevent the runtime from being able to store the object weakly) the object is stored as a non-weak zeroing reference. This means that observers are not required to un-register in their deallocation method.” I’m really disappointed in Apple if this is broken. I don’t care about inline refcounts that much, but it seems like they’re building a really fragile house here. Looking at the zombie FVWebViewIcon and some other FVWebViewIcon, the history is pretty different, so it’s likely taking a completely different code path that Apple hasn’t really tested: there's no retain/release from NSNotificationCenter when FVObject’s implementation is commented out. *** History with FVObject retain/release *** # Event Type ∆ RefCt RefCt Timestamp Responsible Library Responsible Caller 0 Malloc +1 1 00:07.490.521 FileView +[FVIcon allocWithZone:] 1 Retain +1 2 00:07.490.543 FileView -[_FVController _cachedIconForURL:] 2 Release -1 1 00:07.490.545 FileView -[_FVController _cachedIconForURL:] 3 Retain +1 2 00:07.490.545 FileView -[_FVController reload] 4 Retain +1 3 00:07.511.173 FileView -[_FVController _recacheIconsInBackgroundIfNeeded] 5 Release -1 2 00:07.540.340 AppKit loadNib 6 Retain +1 3 00:08.112.437 FileView -[_FVController iconsAtIndexes:] 7 Retain +1 4 00:08.112.595 FileView -[FVIconOperation initWithIcon:view:] 8 Retain +1 5 00:08.123.952 Foundation -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] 9 Release -1 4 00:09.883.125 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 10 Release -1 3 00:11.705.736 Foundation __NSThreadPerformPerform 11 Retain +1 4 00:11.911.026 FileView -[_FVController iconsAtIndexes:] 12 Release -1 3 00:11.915.088 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 13 Retain +1 4 00:12.200.528 FileView -[_FVController iconsAtIndexes:] 14 Release -1 3 00:12.226.420 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 15 Retain +1 4 00:12.232.692 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] 16 Release -1 2 00:12.293.897 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] 17 Retain +1 3 00:12.318.457 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] 18 Release -1 1 00:12.334.116 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] 19 Retain +1 2 00:12.340.832 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] 20 Retain +1 2 00:12.351.941 WebKitLegacy WebDocumentLoaderMac::setDataSource(WebDataSource*, WebView*) 21 Release -1 1 00:12.358.489 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] 22 Release -1 0 00:12.445.285 WebKitLegacy WebDocumentLoaderMac::decreaseLoadCount(unsigned long) 23 Retain +1 2 00:12.445.480 Foundation -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] 24 Retain +1 2 00:12.445.915 FileView -[FVIconOperation initWithIcon:view:] 25 Release -1 1 00:12.446.475 FileView -[FVIconOperation dealloc] 26 Zombie -1 00:12.511.403 FileView -[FVIconOperation hash] *** History without FVObject retain/release *** # Event Type ∆ RefCt RefCt Timestamp Responsible Library Responsible Caller 0 Malloc +1 1 00:04.309.172 FileView +[FVIcon allocWithZone:] 1 Retain +1 2 00:04.311.198 FileView -[_FVController _cachedIconForURL:] 2 Release -1 1 00:04.311.200 FileView -[_FVController _cachedIconForURL:] 3 Retain +1 2 00:04.311.201 FileView -[_FVController reload] 4 Retain +1 3 00:04.334.238 FileView -[_FVController _recacheIconsInBackgroundIfNeeded] 5 Release -1 2 00:04.361.338 AppKit loadNib 6 Retain +1 3 00:04.565.832 FileView -[_FVController iconsAtIndexes:] 7 Retain +1 4 00:04.565.909 FileView -[FVIconOperation initWithIcon:view:] 8 Retain +1 5 00:04.575.665 Foundation -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] 9 Release -1 4 00:05.250.591 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 10 Retain +1 5 00:05.993.302 WebKitLegacy WebDocumentLoaderMac::setDataSource(WebDataSource*, WebView*) 11 Release -1 4 00:06.000.769 Foundation __NSThreadPerformPerform 12 Retain +1 5 00:07.187.582 FileView -[_FVController iconsAtIndexes:] 13 Release -1 4 00:07.190.859 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 14 Release -1 3 00:07.904.926 WebKitLegacy WebDocumentLoaderMac::decreaseLoadCount(unsigned long) 15 Retain +1 4 00:07.930.562 FileView -[FVIconOperation initWithIcon:view:] 16 Release -1 3 00:07.932.780 FileView -[FVIconOperation dealloc] 17 Retain +1 4 00:07.957.346 FileView -[_FVController iconsAtIndexes:] 18 Release -1 3 00:07.980.658 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 19 Retain +1 4 00:08.274.495 FileView -[_FVController iconsAtIndexes:] 20 Release -1 3 00:08.287.621 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 21 Release -1 2 00:08.289.721 FileView -[FVIconOperation dealloc] 22 Retain +1 3 00:08.301.759 FileView -[_FVController iconsAtIndexes:] 23 Release -1 2 00:08.333.803 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) > > BTW, do you know the __sync_fetch_and_add and related built-in functions? Are > they available on 10.6? Or perhaps they are compiler specific? Those look like gcc builtins. The OSAtomic functions might use them under the hood? -- adam ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports.http://sdm.link/zohodev2dev _______________________________________________ Bibdesk-develop mailing list Bibdesk-develop@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-develop