An object that associated to `NSTaggedPointerString` by `objc_setAssociatedObject()` is not released on OS X 10.11.2 (15C50)

Originator:Norio.Nomura
Number:rdar://23914382 Date Originated:16-Dec-2015 01:14 PM
Status:Open Resolved:
Product:OS X SDK Product Version:10.11.2 (15C50)
Classification:Other Reproducible:Always
 
Summary:
An object that associated to `NSTaggedPointerString` by `objc_setAssociatedObject()` is not released on OS X 10.11.2 (15C50)

Steps to Reproduce:
1. Create OS X Playground on Xcode
2. Paste following code to Playground:
```
import Foundation

let assockey = ""

do {
    class Canary {
        deinit {
            print("deinit")
        }
    }
    
    let longerNSString = NSString(format: "longerNSString %d", 1)
    print(longerNSString.dynamicType) // "_NSCFString\n"
    objc_setAssociatedObject(longerNSString, assockey, Canary(), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}

do {
    class Canary {
        deinit {
            print("deinit")
        }
    }
    
    let shorterNSString = NSString(format: "%d", 1)
    print(shorterNSString.dynamicType) // "NSTaggedPointerString\n"
    objc_setAssociatedObject(shorterNSString, assockey, Canary(), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
```


Expected Results:
3. following will be displayed on console:
```
__NSCFString
deinit
NSTaggedPointerString
deist
```

Actual Results:
3. following was displayed on console:
```
__NSCFString
deinit
NSTaggedPointerString
```

Version:
Xcode 7.2 (7C68) & OS X 10.11.2 (15C50)

Notes:


Configuration:


MacBook Pro (Retina, 13-inch, Late 2013) w: OS X OS X 10.11.2 (15C50).spx - configuration file has been successfully uploaded.

Attachments:
'MacBook Pro (Retina, 13-inch, Late 2013) w: OS X OS X 10.11.2 (15C50).spx' was successfully uploaded.

Comments

Reply from Apple:

Tagged pointers are immortal. They were never allocated, so they can never be deallocated (or deinitialized).

A consequence of this is that an object given to a tagged pointer to own will never be released by the tagged pointer's deallocation, because such a thing can't happen.

This applies to all tagged-pointer types, including tagged-pointer numbers.

For the owning object, use an NSMutableString to ensure that the string will not be resolved to a tagged pointer.

By Norio.Nomura at Jan. 5, 2016, 12:07 a.m. (reply...)

Oops. On "Expected Results:", deist is deinit.

By Norio.Nomura at Dec. 16, 2015, 4:29 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!