【发布时间】:2011-01-10 03:51:16
【问题描述】:
我有以下方法:
+(NSMutableDictionary *)getTime:(float)lat :(float)lon {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:hour forKey:@"hour"];
[dictionary setObject:minute forKey:@"minute"];
[dictionary setObject:ampm forKey:@"ampm"];
return dictionary;
}
很多方法都被砍掉了,所以我想我需要池来存放方法中的一些其他东西。这是我的问题。我知道我需要释放以下对象:
[dictionary release];
[pool release];
但是,我不能在返回字典之前释放它,但是一旦我返回它,其余的方法就不会执行。我该怎么办?
【问题讨论】:
-
Objective-C 中的方法从不命名为
get*,除非它们通过引用返回多个值。你也看不到这样的裸冒号。将您的方法命名为timeForLatitude:longitude:。 -
@bbum 感谢您的风格建议!
标签: iphone objective-c cocoa-touch memory-management