This is less a question and more a record of what I've found around the AVCam sample code provided by Apple for iOS4 and 5 camera manipulation. The symptoms of the problem for me were that my app would crash on launching the AVCamViewController after taking around 5-10 photos.
I ran the app through the memory leak profiler and there were no apparent leaks but on inspection with the Activity Monitor I discovered that something called mediaserverd was increasing by 17Mb every time the camera was launched and when it reached ~100Mb the app crashed with multiple low memory warnings.
Apple revised the sample code on Oct 17 2013, fixing the retain cycle. The issue is due to a improper usage of
selfwithin the blocks defined in theinit.Here's the revision description
However, the fix they introduced only works in case of Manual Retain Count. If you are using ARC on the project, apart from getting rid of
release/retaincalls and other obvious things, the storage qualifier forweakSelfhas to be changed from__blockto__weak, like follows.In fact the semantic of
__blockchanged with ARC. In MRC it caused the variable to be weakly referenced, wheres in ARC it does not and__weakmust be used for this purpose.More information about this topic can be found here: How do I avoid capturing self in blocks when implementing an API?
Using the new
initimplementation from the last revision and using__weakinstead of__block, finally caused thedeallocmethod to be properly called.Finally, for those who hate to carry around old legacy code, here's a modernized version of the
AVCamproject: https://github.com/Gabro/AVCamFeatures: