AVAudioRecorder内存泄漏 [英] AVAudioRecorder Memory Leak

查看:204
本文介绍了AVAudioRecorder内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人在那里可以支持我这个...

I'm hoping someone out there can back me up on this...

我一直工作在一个应用程序,允许最终用户记录供以后播放的小音频文件,我在测试内存泄漏的过程。我继续非常一致地碰上了内存泄漏时AVAudioRecorder的一站式方法试图关闭该音频文件它被记录其中。这确实似乎是在框架本身泄漏,但如果我是一个笨蛋,你能告诉我。

I've been working on an application that allows the end user to record a small audio file for later playback and am in the process of testing for memory leaks. I continue to very consistently run into a memory leak when the AVAudioRecorder's "stop" method attempts to close the audio file to which it's been recording. This really seems to be a leak in the framework itself, but if I'm being a bonehead you can tell me.

要说明这一点,我已经工作了一个精简的测试应用程序,并没有什么,但开始/停止录制瓦特/一键preSS。对于simplicty着想,一切都发生在应用程序。委托如下:

To illustrate, I've worked up a stripped down test app that does nothing but start/stop a recording w/ the press of a button. For the sake of simplicty, everything happens in app. delegate as follows:

@synthesize audioRecorder, button;
@synthesize window;

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
 // create compplete path to database
 NSString *tempPath = NSTemporaryDirectory();
 NSString *audioFilePath = [tempPath stringByAppendingString:@"/customStatement.caf"];

 // define audio file url
 NSURL *audioFileURL = [[NSURL alloc] initFileURLWithPath:audioFilePath];

 // define audio recorder settings
 NSDictionary *settings = [[NSDictionary alloc] initWithObjectsAndKeys:
      [NSNumber numberWithInt:kAudioFormatAppleIMA4], AVFormatIDKey,
      [NSNumber numberWithInt:1], AVNumberOfChannelsKey,
      [NSNumber numberWithInt:AVAudioQualityLow], AVSampleRateConverterAudioQualityKey,
      [NSNumber numberWithFloat:44100], AVSampleRateKey,
      [NSNumber numberWithInt:8], AVLinearPCMBitDepthKey,
      nil
 ];

 // define audio recorder
 audioRecorder = [[AVAudioRecorder alloc] initWithURL:audioFileURL settings:settings error:nil];
 [audioRecorder setDelegate:self];
 [audioRecorder setMeteringEnabled:YES];
 [audioRecorder prepareToRecord];

 // define record button
 button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 [button addTarget:self action:@selector(handleTouch_recordButton) forControlEvents:UIControlEventTouchUpInside];
 [button setFrame:CGRectMake(110.0, 217.5, 100.0, 45.0)];
 [button setTitle:@"Record" forState:UIControlStateNormal];
 [button setTitle:@"Stop" forState:UIControlStateSelected];

 // configure the main view controller
 UIViewController *viewController = [[UIViewController alloc] init];
 [viewController.view addSubview:button];

 // add controllers to window
 [window addSubview:viewController.view];
 [window makeKeyAndVisible];

 // release
 [audioFileURL release];
 [settings release];
 [viewController release];

 return YES;
}

- (void) handleTouch_recordButton {
 if ( ![button isSelected] ) {
      [button setSelected:YES];
      [audioRecorder record];

 } else {
      [button setSelected:NO];
      [audioRecorder stop];
 }
}

- (void) dealloc {
 [audioRecorder release];
 [button release];

 [window release];

 [super dealloc];
}

从仪器的堆栈跟踪显示pretty清楚,在AVFoundation code中的closeFile的方法是否漏水......东西。你可以在这里看到仪器会话的屏幕截图:开发者论坛:AVAudioRecorder内存泄漏

任何想法,将大大AP preciated!

Any thoughts would be greatly appreciated!

推荐答案

我看不到任何东西,如果锵没有找到您code泄漏您的code是不太可能出现故障。它看起来像在框架泄漏。

I don't see anything and if Clang doesn't find a leak in your code your code is unlikely to be at fault. It looks like a leak in the framework.

我不会出汗。一个16字节的泄漏,当用户presses停止不容易造成问题。你将不得不停止数千录音前累积泄漏变得大到足以造成问题。小的泄漏只有当它们被迅速重复如在大环中的关注。

I wouldn't sweat it. A 16 byte leak when the user presses stop isn't likely to cause problem. You would have to stop thousands of recordings before the accumulated leaks grew large enough to cause problems. Small leaks are only a concern when they are rapidly repeated such as in a large loop.

这很烦人和美观驱蚊留下一个已知泄漏,但时间就是金钱,我不会浪费要么,除非你知道这是一个显著的问题。

It's annoying and aesthetically repellent to leave a known leak but time is money and I wouldn't waste either on this unless you know it is a significant problem.

这篇关于AVAudioRecorder内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆