Ios4 NSArray释放崩溃

Ios4 NSArray释放崩溃,ios4,nsarray,Ios4,Nsarray,在我的代码中,我创建了5组对象和5个包含这些对象的NSArray。在我的方法结束时,其中两个阵列正常释放,但其他三个使我的应用程序崩溃 创造 UIImageView *image0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TankAxe.png"]]; NSArray *imageArray = [[NSArray alloc] initWithObjects:image0, nil]; NSString *na

在我的代码中,我创建了5组对象和5个包含这些对象的NSArray。在我的方法结束时,其中两个阵列正常释放,但其他三个使我的应用程序崩溃

创造

UIImageView *image0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TankAxe.png"]];  
NSArray *imageArray = [[NSArray alloc] initWithObjects:image0, nil];

NSString *name0 = [NSString stringWithString:@"Pistol"];
NSArray *nameArray = [[NSArray alloc] initWithObjects:name0, nil];

NSNumber *price0 = [NSNumber numberWithInt:100];
NSArray *priceArray = [[NSArray alloc] initWithObjects:price0, nil];

NSNumber *round0 = [NSNumber numberWithInt:0];
NSArray *roundArray = [[NSArray alloc] initWithObjects:round0, nil];

NSNumber *priceRound0 = [NSNumber numberWithInt:0]; 
NSArray *priceRoundArray = [[NSArray alloc] initWithObjects:priceRound0, nil];
释放

[name0 release];
[nameArray release]; //Releases properly

[image0 release];
[imageArray release]; //Releases properly

[price0 release];
NSLog(@"%i",[priceArray retainCount]); //Returns 1
[priceArray release]; //Source of the crash

[round0 release];
[roundArray release]; //Also crashes

[priceRound0 release];
[priceRoundArray release]; //Also Crashes

有人知道如何正确释放包含NSNumbers的阵列吗?

不应释放price0、name0、round0和priceRound0。它们不是用alloc创建的,将由返回它们的方法自动释放

一旦释放了不应该释放的对象,堆就会损坏,程序随时可能崩溃

最简单的调试方法是打开僵尸(提示1):


不应发布price0、name0、round0和priceRound0。它们不是用alloc创建的,将由返回它们的方法自动释放

一旦释放了不应该释放的对象,堆就会损坏,程序随时可能崩溃

最简单的调试方法是打开僵尸(提示1):


请注意,retainCount永远不能返回0。不应该调用该方法的原因之一。实际上,如果retain count为0并且调用了该方法,则应用程序会崩溃,因此调用该方法确实有助于调试。请注意,retainCount永远不能返回0。不应该调用该方法的原因之一。实际上,如果retain count为0并且调用了该方法,则应用程序会崩溃,因此调用该方法确实有助于调试。