你好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...
謝謝。