错误:内存泄漏,数据格式化程序暂时不可用

发布于 2024-08-21 20:55:26 字数 1306 浏览 3 评论 0原文

我正在开发一个测验应用程序。我从 xml 文件中获取问题,解析它并显示随机问题。它们存储在 NSdictionary 和 NSMutableArray 中。该应用程序还播放背景音乐和点击按钮的声音(AVAudioPlayer)。和振动( AudioServicesPlaySystemSound(kSystemSoundID_Vibrate))

在一个特定的函数中,如果我尝试释放我使用的临时变量(IE NSDictionary 和 NSMutableArray),则应用程序会在我第二次到达该函数时崩溃。因此,如果我不释放这些,它可以正常工作,但最终会因“EXC_BAD_ACCESS”错误而崩溃。它不指向任何行或函数。

当我使用“LEAKS”工具时,它显示我有大约 7000 个泄漏。我不明白如何使用该工具,但我确信我没有创建那么多变量,只是创建了一些变量,甚至是我发布的变量。

就在我收到错误“数据格式化程序暂时不可用”时。

知道我做错了什么吗? F1 :)

PS:我的代码都很简单,而且我不知道问题是什么,因此我不知道要在这里发布什么代码? 另外我想知道我是否在函数中创建一个 NSString* 供临时使用,我应该在函数结束时释放它吗?(我确实释放了它) 编辑:

    -(void) loadQuestion
    { 
    strCorrectAnswer = @"";
    int intQuestionNo;
    NSString *strQuestionNo = [[NSString alloc] init];

    // get random question out  the xml file  
NSDictionary *dctQue = [dctQuestions  objectForKey:strQuestionNo];
// blah blah

    // jumble the answers to   be displaed


NSMutableArray *answerJumble = [[NSMutableArray alloc] init];
NSMutableArray *answers =[NSMutableArray arrayWithObjects:[dctQue objectForKey:@"WrongAnswer1"],[dctQue objectForKey:@"WrongAnswer2"],[dctQue objectForKey:@"WrongAnswer3"],[dctQue objectForKey:@"CorrectAnswer"],nil];

 // blah blah

  /*
[strQuestionNo release];
[answers release];
[answerJumble release]; */  

}

I am developing a quiz app. I take questions from a xml file, parse it and display random questions. These are stored in NSdictionary and NSMutableArray. Also the app plays background music and sound for clicking of buttons(AVAudioPlayer). and vibration( AudioServicesPlaySystemSound(kSystemSoundID_Vibrate))

In one particular function if i try to release the temp variables that I use(I.E NSDictionary and NSMutableArray) the app crashes wen i reach that function for the second time. Hence if i don release these, it works fine but eventually crashes with a "EXC_BAD_ACCESS" ERROR. It does not point out to any line or function.

When i used the tool "LEAKS", it showed i was having around 7000 leaks. I don understand how to use that tool but I am sure that i am not creating so many variables, jus a few and even those I release.

And just once i got the ERROR " data formatters temporarily unavailable".

Any Idea what i am doing wrong?? F1 :)

PS: my code is all simple stuff, plus i donno what the problem is hence i donno what code to post here?
Also i would like to know if i create a NSString* in a function for temp use should i release it at the end of the function?(i do release it)
EDIT:

    -(void) loadQuestion
    { 
    strCorrectAnswer = @"";
    int intQuestionNo;
    NSString *strQuestionNo = [[NSString alloc] init];

    // get random question out  the xml file  
NSDictionary *dctQue = [dctQuestions  objectForKey:strQuestionNo];
// blah blah

    // jumble the answers to   be displaed


NSMutableArray *answerJumble = [[NSMutableArray alloc] init];
NSMutableArray *answers =[NSMutableArray arrayWithObjects:[dctQue objectForKey:@"WrongAnswer1"],[dctQue objectForKey:@"WrongAnswer2"],[dctQue objectForKey:@"WrongAnswer3"],[dctQue objectForKey:@"CorrectAnswer"],nil];

 // blah blah

  /*
[strQuestionNo release];
[answers release];
[answerJumble release]; */  

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法言说的痛 2024-08-28 20:55:26

您应该阅读一些有关 Cocoa 内存管理的内容。请参阅 Mac 开发人员中心 或 < a href="http://cocoadevcentral.com/d/learn_objectivec/" rel="nofollow noreferrer">Cocoa Dev Central 的教程。 iPhone上的内存管理并不难,可惜的是不断摸索代码。

You should read something about memory management in Cocoa. See the Mac Developer Center or the tutorial at Cocoa Dev Central. Memory management on iPhone is not hard, it’s a pity to code by trial and error.

Oo萌小芽oO 2024-08-28 20:55:26

经过一番挖掘后,问题出在必须重播声音文件的地方。如果我按下一个按钮,在声音文件完成播放之前,如果我再次按下,则声音文件只会播放一次。导致内存泄漏 3000。

如果我执行此操作两次,则应用程序会在泄漏 6425 后崩溃。因此错误 -“数据格式化程序当前不可用”。(我猜)

well after a bit of digging, the problem was wen the sound file had to be replayed. If i press a button and before the sound file finishes playing if i press again, the sound file was being played just once. Resulting in a memory leak of 3000.

IF i did this twice the app wud crash after a leak of 6425. Hence the ERROR-"data formatters currently not available".(i guess)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文