gpt4 book ai didi

ios - 我应该在声音中发布 NSBundle 吗?

转载 作者:行者123 更新时间:2023-11-28 18:44:40 25 4
gpt4 key购买 nike

我应该在下面的代码中释放 NSBundle 吗? NSURL 是否也应该发布?我很困惑。

NSBundle  *mainBundle = [NSBundle mainBundle];
NSError *error;
NSURL *audioURL = [NSURL fileURLWithPath:[mainBundle pathForResource:@"count_in" ofType: @"mp3"]];
AVAudioPlayer *player1 = [(AVAudioPlayer*) [AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error];
self.player = player1;
[self.player play];
[player1 release];

最佳答案

你不应该释放 NSBundleNSURL 实例,因为你还没有分配它们。

来自苹果文档。

You take ownership of an object if you create it using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message.

You use release or autorelease to relinquish ownership of an object. autorelease just means “send a release message in the future” (specifically: when the used autorelease pool receives a drain message—to understand when this will be, see “Autorelease Pools”).

我强烈建议您清除内存管理概念。

阅读关于苹果的文章 Memory Management Rules

关于ios - 我应该在声音中发布 NSBundle 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6178948/

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