Bug 55010 - App crashes after taking more than 30 photos one after another
Summary: App crashes after taking more than 30 photos one after another
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 10.10 (d15-2)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL: https://github.com/erossini/XamarinCa...
Depends on:
Reported: 2017-04-11 09:45 UTC by Enrico
Modified: 2017-06-19 16:03 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Xcode log (799.82 KB, text/plain)
2017-04-11 09:45 UTC, Enrico
Another Xcode log (2.49 MB, text/plain)
2017-04-11 09:46 UTC, Enrico

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Enrico 2017-04-11 09:45:05 UTC
Created attachment 21422 [details]
Xcode log

If you take photos one after another, after about 30 photos the app crashes. At the beginning I thought it was a problem with Plugin.Media  by James Montemagno or Refractored.MvvmHelpers. Then I implemented a native code to take photo:

using System;
using cameratest.iOS;
using Foundation;
using UIKit;
using Xamarin.Forms;

[assembly: Xamarin.Forms.Dependency(typeof(Camera_iOS))]
namespace cameratest.iOS
    public class Camera_iOS : ICamera
        static UIImagePickerController picker;
        static Action<NSDictionary> _callback;

        static void Init()
            if (picker != null)

            picker = new UIImagePickerController();
            picker.Delegate = new CameraDelegate();

        class CameraDelegate : UIImagePickerControllerDelegate
            public override void FinishedPickingMedia(
                                 UIImagePickerController picker, NSDictionary info)
                var cb = _callback;
                _callback = null;


        public static void TakePicture(UIViewController parent, 
                                       Action<NSDictionary> callback)
            picker.SourceType = UIImagePickerControllerSourceType.Camera;
            _callback = callback;
            parent.PresentModalViewController(picker, true);

        public static void SelectPicture(UIViewController parent, 
                                         Action<NSDictionary> callback)
            picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
            _callback = callback;
            parent.PresentModalViewController(picker, true);

        public void TakePicture()
            var rc = UIApplication.SharedApplication.KeyWindow.RootViewController;
            TakePicture(rc, (obj) =>
                var photo = obj.ValueForKey(
                         new NSString("UIImagePickerControllerOriginalImage")) as UIImage;
                var documentsDirectory = 

                // hardcoded filename, overwritten each time
                string jpgFilename = System.IO.Path.Combine(documentsDirectory, 
                NSData imgData = photo.AsJPEG();
                NSError err = null;
                if (imgData.Save(jpgFilename, false, out err))
                    Console.WriteLine("saved as " + jpgFilename);
                    Console.WriteLine("NOT saved as " + 
                         jpgFilename + " because" + err.LocalizedDescription);

The problem is still there. After about 26-28 photos, I receive a memory error from ReceiveMemoryWarning and after 3-4 photos the app crashes.

If you want to replicate the error, I created a test project for you on GitHub https://github.com/erossini/XamarinCameraTest. With my iPad Air or iPad Pro after about 30 photos (video iPad Air https://youtu.be/od0Qx5YdMo0 - iPad Pro https://youtu.be/0IReKcFyPcc). All devices are iOS ver. 10.3.1 and they have enough space to storage photos.

I also opened some posts:
- https://forums.xamarin.com/discussion/92808/xamarin-forms-and-plugin-media-after-about-20-photos-something-crashes#latest
- http://stackoverflow.com/questions/43301608/xamarin-forms-and-plugin-media-after-about-20-photos-something-crashes
- https://github.com/jamesmontemagno/MediaPlugin/issues/219

If I use Xamarin Profiler, the Profiler crashed after about 30 photos with a error https://i.stack.imgur.com/wrIXN.png
Comment 1 Enrico 2017-04-11 09:46:47 UTC
Created attachment 21424 [details]
Another Xcode log
Comment 2 Enrico 2017-04-11 09:50:15 UTC
I didn't have this behaviour in previous version. For example I have a project created last year in August and the users can take a lot of photos without any problem.
Comment 3 Enrico 2017-04-11 09:54:42 UTC
Some more info

Xcode ver. 8.3.1 (8E1000a)

=== Xamarin Studio Enterprise ===

Version 6.3 (build 863)
Installation UUID: 8a4112a0-ccda-4b27-931b-b7e62e9fac26
	Mono 4.8.0 (mono-4.8.0-branch/9d74414) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000524

=== NuGet ===


=== Xamarin.Profiler ===

Version: 1.4.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin Inspector ===

Version: 1.2.1
Hash: 0ea0a12
Branch: d15-1
Build date: Thu, 06 Apr 2017 20:24:44 GMT

=== Apple Developer Tools ===

Xcode 8.3.1 (12170)
Build 8E1000a

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise)
Hash: a04678c2
Branch: d15-1
Build date: 2017-03-28 14:05:38-0400

=== Xamarin.Android ===

Version: (Visual Studio Enterprise)
Android SDK: /Users/enricorossini/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		6.0 (API level 23)
		7.0 (API level 24)

SDK Tools Version: 25.1.7
SDK Platform Tools Version: 24.0.1
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:

=== Build Information ===

Release ID: 603000863
Git revision: a2163670efe259c85cd8f335d95b175068fbbe2a
Build date: 2017-04-03 14:33:15-04
Xamarin addins: 2045d688ea1420e0381b473360ca62a763eb7d04
Build lane: monodevelop-lion-d15-1

=== Operating System ===

Mac OS X 10.12.4
Darwin Enricos-MacBook-Air.local 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

MFractor 2.10.05
Gorilla Player
Comment 4 Timothy Risi 2017-04-13 16:52:14 UTC
I downloaded the Github sample and it did crash for me as well, though it took ~80 pictures before it crashed.  Have you tested a native app in xcode doing the same thing to see if it's an issue in the newer version of iOS or Xcode?  I saw in one of your comments in the MediaPlugin issues that you thought it might be an Xcode issue.
Comment 5 Enrico 2017-04-13 16:57:31 UTC
Hi Timothy,
thanks for your message.
I'm really happy to hear you have the same problem, I'm not mad :)

I didn't check the code in Xcode: I bought a virtual mac and I should try this week end. My consideration about Xcode is because last year in August I created an app where users can take a lot of pictures. From august until two weeks ago, I've never update it and the app was working fine. Two weeks ago, I changed the url for webapi in it and I rebuilt and deployed to my users this app. After three hours they called me to highlight this problem and then I started to investigate more.
Comment 6 Vincent Dondain [MSFT] 2017-05-19 17:49:26 UTC
Hi Enrico,

As a followup to Tim's question, did you have a chance to try reproducing the issue with a native project using Xcode?

It does seem like a native issue.
Comment 7 Alex Soto [MSFT] 2017-06-19 16:03:06 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and re-open the bug report. Thanks!