我对 Objective-C 编程很陌生,对象的释放是我最头疼的事情。我总是怀疑需要发布什么,而我最终发布了错误的变量并导致 BAD EXEC 崩溃。我已经阅读了苹果的内存管理指南,但我不能总是从他们的示例到我的代码。
其中一种情况是我的单身人士(我是个单身人士)。
我有一个这样的定义:
static Configuration* _instance;
+(Configuration*)getInstance{
if (_instance == NULL){
_instance = [Configuration alloc];
[_instance initConfig];
}
return _instance;
}
在我的代码中,我这样使用它:
//Store configuration
Configuration* conf = [Configuration getInstance];
conf.userName = self.userName.text;
conf.cellPhone = self.phoneNumber.text;
我需要释放“conf”变量吗?
我应该什么时候释放 _instance?
由于我在 iPhone 上运行此代码,我未发布的变量会发生什么?它们会影响 iPhone 的性能吗?