我目前正在为iPhone开发我的第一个应用程序,我已经差不多完成了,但我遇到了内存管理等问题。请记住,我对Java很好,我只学习了Objective C约4天。Objective C内存问题
所以,确切的问题在于这个领域(在星号之间)。 注意:如果重要的话,所有的代码都在一个大的游戏循环中。
else
{
***********************************
NSString *rand = [NSString stringWithFormat:@"%@", randNumberS];
while(lastTime + interval >= currentTime)
{
!!!!!!!!!NSString *user = [NSString stringWithFormat:@"%@", userText];
if([user isEqualToString: rand])
{
***********************************
score += 10;
randNumberS = nil;
timeToGenerateNum = true;
bottomClear = true;
break;
}
else
{
//NSLog(@"%@ != %@, %i", userText, randNumberS, score);
}
}
NSLog(@"Game Over! Your score was %i!", score);
}
}
每次我才启用僵尸我跑了(注:该代码跑了几秒钟的BTW),我得到了一个Thread 6: Program received signal: "EXC_BAD_ACCESS"
在标有行“!”。启用僵尸后,它会运行几秒钟,然后停止工作,并在控制台中显示消息-[CFString respondsToSelector:]: message sent to deallocated instance 0x11168440
。它也标记与“!”相同的行我注意到这两个问题,他们都指向糟糕的内存管理,我试图释放NSString对象,但我的程序不会让我释放对象(注意:我得到这个错误信息"release" is unavailable: not available in automatic reference counting mode
)。
任何帮助将不胜感激,谢谢!
编辑:
userText以各种数量的方法中使用,但主要是在这一个。
-(IBAction)button1Clicked:(id)sender
{
if(userText == nil)
{
userText = [NSString stringWithFormat:@"%i", 1];
}
else
{
userText = [NSString stringWithFormat:@"%@%i",userText , 1];
}
bottomLabel.text = userText;
NSLog(@"Test 1");
}
它看起来像在userText的实例不再你身边,你可以显示如该被初始化,以及它是如何在这个代码的其他地方处理? – 2012-07-07 16:41:04