views:

14

answers:

1

i have this code in my overridden drawRect method

NSDate *date = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned int unitFlags = NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;
NSDateComponents *comp = [calendar components:unitFlags fromDate:date];
NSInteger h = [comp hour];
NSInteger m = [comp minute];
NSInteger s = [comp second];
NSLog(@"%i,%i,%i", h,m,s);
NSLog(@"test");
[date release];
[calendar release];
[comp release];

I am calling drawRect using setNeedsDisplay from my custom method (timer based after each 1 secon). It runs only once and then app exit automatically. If i comment out all the code and just write
NSLog(@"test");
then application works ok, it logs "test" after each 1 sec.

A: 

All three of the objects you're releasing are autoreleased. You shouldn't call release on them explicitly.

warrenm
how to find which one is autoreleased?
coure06
It's all in the method names. Read this document for details: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-BEHDEDDB
warrenm