I\'m working on a custom video player for iOS using AVFoundation. The idea is to be able to switch to a different video with a gesture (tap, swipe, whatever). Right
I FINALLY SOLVED IT. The design I had was indeed very poor, It had a very bad memory management and so on. What I did was, instead of releasing everything I could, including views, layers, players, assets, etc, I just created a method to update the player's asset and item, recycling the player, views, layers, etc.
[player pause];
contentURL = [[NSURL alloc] initFileURLWithPath:newPath];
AVAsset *newAsset = [AVURLAsset URLAssetWithURL:contentURL options:nil];
AVPlayerItem *newPlayerItem = [AVPlayerItem playerItemWithAsset:newAsset];
[player replaceCurrentItemWithPlayerItem:newPlayerItem];
[contentURL release];
And now it's working wonders. Thank you all for your help.
There are 2 places in the code where you have retained an object, and I don't see the corresponding release anywhere in the code you have posted. I would start by making sure that the memory reference count increments and decrements are all appropriately balanced.
The first retain looks suspicious to me. Generally you should first autorelease the variable you are assigning to and then retain as follows:
[systemPath autorelease];
systemPath = [aContentURL retain]
In the above code is easy to see that the retain/release matching is maintained, and is far less error prone than other schemes. Note that if systemPath
== aContentURL
the object will not be released.