You must not release components
yourself at all as it's set to autorelease by the NSCalendar
object.
I suspect your leak is coming from your NSDate
object that you pass to that line of code. You should probably assign that to a local variable, pass it to the [cal components]
method then release the local variable:
NSDate *today = [[NSDate alloc] init];
NSDateComponents *components = [cal components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:today];
[today release];
Or, set the NSDate
object itself to autorelease as you pass it as you are doing, use [NSDate date]
, which as David Gelhar commented will generate an autoreleased object, like so:
NSDateComponents *components = [cal components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:[NSDate date]];