我已经完成了我的项目的编码,但是当我在客户端提交我的源代码时,它已经过测试,然后检测到内存泄漏。我已经在Instruments using Leaks
. 我遇到的问题是在我的AVPlayer
和我的AVAudioPlayer
以及我的AppDelegate
. 我应该为此找到替代品吗?还是我的代码有问题?
下面是我的代码(ARC
顺便说一下我正在使用):
---> AppDelegate
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RootViewAppDelegate class]));
}
}
和
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[window makeKeyAndVisible];
---> AVPlayer
self.moviePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:moviePath]];
---> AVAudioPlayer
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/Normal.wav"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;
//Initialize our player pointing to the path to our resource
BGMplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];
if( err ){
//bail!
NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
//set our delegate and begin playback
BGMplayer.delegate = self;
[BGMplayer play];
BGMplayer.numberOfLoops = -1;
BGMplayer.currentTime = 0;
BGMplayer.volume = 1.0;
}
以下是我检测上述内容的方法:
希望有人能帮助我,这是我第一次检测内存泄漏。所以希望得到您的指导。非常感谢您。