Memory leaks when calling -[EKEvent endDate] in iOS 4.3

Originator:adubrovsky
Number:rdar://9888640 Date Originated:03-Aug-2011 05:11 PM
Status:Duplicate/9053792 Resolved:
Product:iPad SDK Product Version:4.3
Classification:Serious Bug Reproducible:Always
 
Summary:

Instruments (v. 4.0) detect a memory leak in -[EKEvent endDate] in iOS 4.3. The planner application I'm developing I need to use the Event Kit. The app behaves oddly: Some views disappear from the screen with no visible reasons, the app sometimes crashes. I started an investigation and the Leaks instrument detected a leak in the endDate method. After replacing

NSDate *endDate = [event endDate];

with a fixed date, the abnormal behavior stopped. I was able to reproduce the bug by creating a brand new project which fetches an event and displays the endDate in a label when a button is pressed.

Steps to Reproduce:

To reproduce the bug the simplest way is the following

1. Create a new project targeted for iPad and based on the View-based application template.
2. Add the Event Kit Framework.
3. Open the nib-file with main view.
4. Add a label and a button.
5. Add and connect an outlet named `label' for the label and an action named `displayEndDate' for the button.
6. Type following code as an implementation of the action.

- (IBAction)displayEndDate:(id)sender {
    EKEventStore *store = [[EKEventStore alloc] init];
    // Create the predicate's start and end dates.
    CFGregorianDate gregorianStartDate, gregorianEndDate;
    CFGregorianUnits startUnits = {0, 0, -30, 0, 0, 0};
    CFGregorianUnits endUnits = {0, 0, 15, 0, 0, 0};
    CFTimeZoneRef timeZone = CFTimeZoneCopySystem();
    
    gregorianStartDate = CFAbsoluteTimeGetGregorianDate(
                                                        CFAbsoluteTimeAddGregorianUnits(CFAbsoluteTimeGetCurrent(), timeZone, startUnits),
                                                        timeZone);
    gregorianStartDate.hour = 0;
    gregorianStartDate.minute = 0;
    gregorianStartDate.second = 0;
    
    gregorianEndDate = CFAbsoluteTimeGetGregorianDate(
                                                      CFAbsoluteTimeAddGregorianUnits(CFAbsoluteTimeGetCurrent(), timeZone, endUnits),
                                                      timeZone);
    gregorianEndDate.hour = 0;
    gregorianEndDate.minute = 0;
    gregorianEndDate.second = 0;
    
    NSDate* startDate =
    [NSDate dateWithTimeIntervalSinceReferenceDate:CFGregorianDateGetAbsoluteTime(gregorianStartDate, timeZone)];
    NSDate* endDate =
    [NSDate dateWithTimeIntervalSinceReferenceDate:CFGregorianDateGetAbsoluteTime(gregorianEndDate, timeZone)];
    
    CFRelease(timeZone);
    
    // Create the predicate.
    NSPredicate *predicate = [store predicateForEventsWithStartDate:startDate endDate:endDate calendars:nil];
    
    // Fetch all events that match the predicate.
    NSArray *events = [store eventsMatchingPredicate:predicate];
    [store release];
    EKEvent *event = [events objectAtIndex:0];
    label.text = [NSDateFormatter localizedStringFromDate:event.endDate dateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterLongStyle];
}

7. Make sure you have some events for the period from the code above in the calendar.
8. Build and run the project using the Instruments.
9. Choose Leaks template.
10. Tap the button in the application.

Expected Results:

No memory leaks.

Actual Results:

Leaked object __NSDate of 16 Bytes with -[EKEvent endDate] as responsible frame

Regression:

The problem occurs on a device as well as in the simulator.

Notes:

No workaround found.
Apple says it's a duplicate of rdar://problem/9053792

Comments


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!