Leak in NSDocument Edge Case
Leak in NSDocument Edge Case
- Subject: Leak in NSDocument Edge Case
- From: Jerome Krinock <email@hidden>
- Date: Fri, 30 Jun 2017 14:53:12 -0700
It looks to me that, in the edge case where user clicks File : Duplicate and
then enters a file path/name that already exists in the filesystem, so that
Cocoa prompts to "Replace" or "Cancel", the new NSDocument object gets four (4)
unbalanced retains, and therefore leaks. This is reproducible in macOS 10.12
or 10.13, Swift or Objective-C, ARC or not.
I say this because a document which has has been created in this way does not
dealloc as documents normally do when closed (or a few seconds thereafter), but
it does dealloc if I send it four unbalanced -release messages. And if I send
it five unbalanced -release messages, a zombie squeals as expected.
The `leaks` command-line tool indicates 0 leaks before the File : Duplicate,
and 12 leaks after closing the duplicated (and I think leaky) document,
including some leaked code blocks, although none of the leaks are a
document/NSDocument object per se.
If no one can find a mistake in my analysis I’ll file a bug.
Jerry Krinock
In case you want to see for yourself:
https://youtu.be/zSQ1hY7JVZs (03:49)
https://github.com/jerrykrinock/LeakyDocumentDemo
ACA80004:~ jk$ leaks 4800
Process: LeakyDocSwiftDemo [4800]
Path:
/Users/jk/Library/Developer/Xcode/DerivedData/LeakyDocumentDemo-ctlrylejnnaaxqddgjsbbjsrcnzy/Build/Products/Debug/LeakyDocSwiftDemo.app/Contents/MacOS/LeakyDocSwiftDemo
Load Address: 0x100000000
Identifier: com.sheepsystems.LeakyDocumentSwiftDemo
Version: 1.0 (1)
Code Type: X86-64
Parent Process: debugserver [4801]
Date/Time: 2017-06-30 14:27:22.798 -0700
Launch Time: 2017-06-30 14:24:29.663 -0700
OS Version: Mac OS X 10.12.6 (16G23a)
Report Version: 7
Analysis Tool: /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version: Xcode 8.3.3 (8E3004b)
----
leaks Report Version: 2.0
Process 4800: 45412 nodes malloced for 6440 KB
Process 4800: 12 leaks for 608 total leaked bytes.
Leak: 0x608000221f40 size=32 zone: DefaultMallocZone_0x100ea5000 CFString
(Storage) C CoreFoundation length: 4 has-length-byte: "doc1"
Leak: 0x608000222c40 size=32 zone: DefaultMallocZone_0x100ea5000
__NSExactBlockVariable__ __block variable CoreFoundation
0x00000000 0x00000000 0x00222c40 0x00006080 ........@,"..`..
0x21000004 0x00000020 0x0045d200 0x00006000 ...! .....E..`..
Leak: 0x608000222c60 size=32 zone: DefaultMallocZone_0x100ea5000
__NSExactBlockVariable__ __block variable CoreFoundation
0x00000000 0x00000000 0x00222c60 0x00006080 ........`,"..`..
0x21000004 0x00000020 0x00104f01 0x00006000 ...! ....O...`..
Leak: 0x608000256620 size=48 zone: DefaultMallocZone_0x100ea5000
__NSMallocBlock__ ObjC CoreFoundation AppKit __75-[NSWindow
_titlebarEditingDidEndNormally:title:editingRange:grantHandler:]_block_invoke_3
0x7fff8cb68ce9
Leak: 0x60800025a280 size=48 zone: DefaultMallocZone_0x100ea5000
__NSMallocBlock__ ObjC CoreFoundation AppKit __77-[NSDocument
duplicateDocumentWithDelegate:didDuplicateSelector:contextInfo:]_block_invoke.2577
0x7fff8c7f24a5
Leak: 0x60800025d220 size=48 zone: DefaultMallocZone_0x100ea5000
__NSMallocBlock__ ObjC CoreFoundation AppKit
__81-[NSDocument(NSDocumentSerializationAPIs)
_activityCompletionHandlerForActivity:]_block_invoke 0x7fff8c89437b
Leak: 0x60800025d2e0 size=48 zone: DefaultMallocZone_0x100ea5000
NSMutableArray ObjC CoreFoundation item count: 5
Leak: 0x608000279e80 size=64 zone: DefaultMallocZone_0x100ea5000 CFString
ObjC CoreFoundation length: 4 mutable non-inline: "doc1"
Leak: 0x608000462880 size=64 zone: DefaultMallocZone_0x100ea5000
_NSDocumentActivity ObjC AppKit
0xa9241079 0x001dffff 0x00000001 0x00000000 y.$.............
0x00000000 0x00000000 0x00464400 0x00006080 .........DF..`..
0x00000101 0x00000000 0x0025d2e0 0x00006080 ..........%..`..
0x00465c00 0x00006080 0x00000000 0x00000000 .\F..`..........
Leak: 0x608000464400 size=64 zone: DefaultMallocZone_0x100ea5000
__NSMallocBlock__ ObjC CoreFoundation AppKit __77-[NSDocument
duplicateDocumentWithDelegate:didDuplicateSelector:contextInfo:]_block_invoke_4
0x7fff8c7f1dd9
Leak: 0x608000465c00 size=64 zone: DefaultMallocZone_0x100ea5000
__NSMallocBlock__ ObjC CoreFoundation AppKit __77-[NSDocument
duplicateDocumentWithDelegate:didDuplicateSelector:contextInfo:]_block_invoke.2594
0x7fff8c7f27e2
Leak: 0x608000466440 size=64 zone: DefaultMallocZone_0x100ea5000
__NSMallocBlock__ ObjC CoreFoundation AppKit __75-[NSWindow
_titlebarEditingDidEndNormally:title:editingRange:grantHandler:]_block_invoke.4316
0x7fff8cb68a73
ACA80004:~ jk$
P.S. Despite all of the Objective-C in that report, I assure you this is my
Swift target running :))
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden