你好Stackoverflow家庭成员!iPhone内存管理
我有关于iPhone内存管理的问题。
我所做的理解是以下方法
-(void) dealloc
{
// something else to release whatever
// such as Object Created using keyword 'alloc'
// but also Object destroy here its retain value reaches iff 0
// if I do put here NSLog(@"%d", [obj retainCount]); and when it reaches
// not equal to 0 means failure with memory leak.
[super dealloc];
}
所以我是明白了吧?或者即使保留计数在这里达到0以上,它仍然很亮?
我之所以问这个问题,因为,
我
NSLog(@"%d", obj.retainCount);
检查,以检查保留对象的数量和接收到的值3。于是,我就在这里释放的3倍,使这里retainCount等于0,但编译器给我提供了严重错误。
请问,我是新来的内存解除分配和保留,释放。我用
对象是 '的UIImageView' 对象,并创建另一个实例是,
UIImageView *imageView = //da da~ with UIImage
UIImageView *instance;
// at this point retain count was '1'
instance = imageView;
//[imageView retain];
// at this point retain count was '2'
[self.view addSubView: imageView];
// at this point retain count was '3'
[imageView release];// crashes
// at this point retain count was '2'
,但如果我这样做
// but if I add retain on the 'instance = imageView'
// such as
instance = imageView; // then
[imageView retain];
// works but still count is 2...
谢谢。