Memory Leak when using NSDate in NSPredicate and Core Data on iOS 9

Originator:bstovold
Number:rdar://23025446 Date Originated:8/10/2015
Status:Open Resolved:
Product:iOS SDK Product Version:9.0
Classification:Serious Bug Reproducible:Always
 
Summary:
On iOS 9.0, when an NSDate is used in a predicate for an NSFetchRequest executed in a child context, the date is retained one too many times and it leaks.

This does not occur on iOS 8.3 or below.

Steps to Reproduce:
1. Clone https://github.com/followben/DateLeaks
2. Build/Run or Profile the app using the Leaks instrument on iOS 8.3
3. Build/Run or Profile the app using the Leaks instrument on iOS 9.0

Expected Results:
On both iOS 9 and iOS 8, NSLog indicates a retainCount of 1 and the Leaks Instrument detects no leaks.

Actual Results:
On iOS 8, NSLog indicates a retainCount of 1 and the Leaks Instrument detects no leaks.

However, on iOS 9, NSLog indicates a retainCount of 2 and the Leaks Instrument indicates a leak.

Version:
iOS 9.0.2 (13A452), Xcode 7.0 (7A218)

Notes:
If the fetch request is executed on the parent context the date does not leak. The ConcurrencyType of the child context does not seem to impact this behaviour.

I've also tested this with numerous other types (NSString, NSNumber) and this only seems to occur with NSDate.

Configuration:
iOS Simulator, iPhone 5, iPhone 6

Comments

Also with Strings

Same here in iOS 9.1, also with this example:

    request.predicate = [NSPredicate predicateWithFormat: @"id =[c] %@",dictionary[@"id"]];

But not with

    request.predicate = [NSPredicate predicateWithFormat: @"id =[c] %@",@"randomstring"];

Confirmed on iOS 9.1

Happy to have found this, also confirmed to happen on iOS 9.1 under the same conditions.


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!