gpt4 book ai didi

objective-c - 使用 AVAudioPlayer 发生内存泄漏

转载 作者:行者123 更新时间:2023-12-03 16:53:03 25 4
gpt4 key购买 nike

我正在使用仪器分析 Objective-C++ 代码中的泄漏,我得到了以下结果:

Leaked Object   Address Size    Responsible Library Responsible Frame
Malloc 32 Bytes,0x8135bc0 32 Bytes AudioToolbox SimAggregateDevice::SimAggregateDevice(__CFString const*, __CFString const*, long&)
__NSCFDictionary,0x8135be0 48 Bytes AudioToolbox CreateDictionaryForDevice(unsigned long)
Malloc 32 Bytes,0x8135c10 32 Bytes AudioToolbox CreateDictionaryForDevice(unsigned long)
Malloc 32 Bytes,0x8135c30 32 Bytes AudioToolbox CreateDictionaryForDevice(unsigned long)
Malloc 48 Bytes,0x8135c50 48 Bytes AudioToolbox SimAggregateDevice::SimAggregateDevice(__CFString const*, __CFString const*, long&)
__NSCFDictionary,0x813a820 48 Bytes AudioToolbox SimAggregateDevice::SimAggregateDevice(__CFString const*, __CFString const*, long&)
__NSCFArray,0x813a850 32 Bytes AudioToolbox SimAggregateDevice::SimAggregateDevice(__CFString const*, __CFString const*, long&)
__NSCFDictionary,0x813a870 48 Bytes AudioToolbox CreateDictionaryForDevice(unsigned long)
Malloc 32 Bytes,0x813a8a0 32 Bytes AudioToolbox SimAggregateDevice::SimAggregateDevice(__CFString const*, __CFString const*, long&)
Malloc 32 Bytes,0x813a8d0 32 Bytes AudioToolbox CreateDictionaryForDevice(unsigned long)

我认为这与我编写的在应用程序启动时播放声音的代码有关。我这样做:这个方法在 applicationDidFinishLaunching::

中调用
- (void)playJingle {
// This is a detached thread so I need a new pool.
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

// This audio player will be released in audioPlayerDidFinishPlaying.
NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:@"jingle" ofType:@"m4a"];
AVAudioPlayer *av = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];
[av setDelegate:self];
[av play];

// Release.
[pool release];
}

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer*)av successfully:(BOOL)flag
{
// Release the AVAudioPlayer.
[av release];
}

在后台线程中(使用 PerformSelectorInBackground:withObject: 调用)。我错过了什么吗?为什么我会有这些泄漏?谢谢!

最佳答案

您是否尝试过在设备上运行该应用程序? AVAudioPlayer 在模拟器上进行内存泄漏检测时很容易出现误报...

Here's a very similar question with a similar looking leak report

关于objective-c - 使用 AVAudioPlayer 发生内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5284419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com