我在类中的方法分配内存初始化:释放内存初始化
UIColor * customBlue;
UIColor * customRed;
@implementation UIColorConstants
+ (void)initialize{
if (self == [UIColorConstants class]) {
customBlue = [[UIColor alloc]initWithRed:0 green:0.137 blue:0.584 alpha:1];
customRed = [[UIColor alloc]initWithRed:.91 green:0.067 blue:0.176 alpha:1];
}
}
+ (UIColor *)getCustomRed{
return customRed;
}
+ (UIColor *)getCustomBlue{
return customBlue;
}
@end
哪里是释放所分配的内存,因为没有对应的初始化自动调用最好/正确的位置?
+1我以前没有听说过'atexit'。整齐! – 2010-10-28 16:25:54
如果分配和返回同一个实例,延迟加载肯定是一种更好的方法 - 谢谢你的回答/建议。 – 2010-10-28 16:44:25