Memory leak in AudioToolbox AVAudioPlayer library

Is there a memory problem with the AVAudioPlayer object? I get a memory leak when using AVAudioPlayer in the simulator. It doesn't matter how I created AVAudioPlayer. I used initWithContentsOfURL and InitWithData . The following is a snippet of code. Full @Github project https://github.com/docchang/MemoryLeakAVAudioPlayer

 NSError *error; NSURL *playerURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Bell" ofType:@"m4a"]]; self.playerWithURL = [[AVAudioPlayer alloc] initWithContentsOfURL:playerURL error:&error]; if (!playerWithURL) { NSLog(@"no %@.%@: %@",@"Introduction2", @"m4a", [error localizedDescription]); } playerWithURL.volume = 0.9f; playerWithURL.numberOfLoops = 0; [playerWithURL play]; 

However, when testing on the device there is no memory leak. This problem is starting to lean toward the problem with the AudioToolBox library, but I just want to confirm it with the help of stackoverflow users.

0
source share
2 answers

When using AVAudioPlayer, I get the same memory leak. I saw several posts about similar encounters of this leak with the AVAudioPlayer and VideoPlayer libraries on the Internet. It seems that the problem is with the library itself (blame Apple):

Edit: also the leak vision disappears when the target is running on the device.

+3
source

Just passed the test, as I ran into the same problem. The tools showed a leak at the beginning of the application when the sound was played using AVAudioPlayer. It was registered only once at the beginning. Sounds created subsequently did not leak further.

When I ran the same version of the application on my iPhone using tools, there was no leak at all.

I am running iOS 11.2.5 and Xcode Deployment Target - 11.0

This seems to be just an Xcode bug, but could be related to MacOS.

0
source

Source: https://habr.com/ru/post/1435761/


All Articles