【发布时间】:2012-10-29 20:55:07
【问题描述】:
@property ( nonatomic, strong ) NSURL * urlPath;
self.urlPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bark" ofType:@"caf"]];
运行 ARC,部署目标 4.3。 Instruments 在 self.urlPath = line 上给出了泄漏。
self.urlPath 稍后会在视图出现后用于设置 AVSoundPlayer。现在声音播放器上没有显示泄漏,仅在此 NSURL 行上。音频播放,但是当视图被弹出时会发生内存泄漏。
我在这方面的任何想法 > 12 小时现在......
【问题讨论】:
-
尝试使用
URLForResource:withExtension:方法而不是pathForResource:,播放器也可能会泄漏。 -
所有 iOS SDK 版本都有泄漏吗?
-
您为什么使用
URLWithString:?您通常使用fileURLWithPath:将文件路径转换为NSURL实例。不确定这是否与您的泄漏有关,但值得一看。 -
我已将 setupSound 方法更改为: - ( void ) setupSound { NSURL * urlPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bark" ofType:@"caf"] ]; self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:urlPath error:nil]; [self.player setVolume:0.5f];但是我现在在 NSURL 行上得到了 100% 的泄漏。音频播放器的属性是这样的:@property (nonatomic, strong) AVAudioPlayer * player;我必须使用 4.3 部署目标并且我正在使用 ARC
-
另外,别忘了致电
[super viewDidAppear:animated]和[super viewWillDisappear:animated]。
标签: ios nsstring avaudioplayer memory-leaks nsurl