Skip to content

Commit

Permalink
Correct ios freezing when take photo. (MvvmCross#4033)
Browse files Browse the repository at this point in the history
MvvmCross#3517
It was caused by garbage collection. Events was never thrown
Remplacing WeakSubsribe by strong subscribe. It prevents the garbage collection
  • Loading branch information
PierreYvesBl authored Jan 2, 2021
1 parent 348345c commit aae2e82
Showing 1 changed file with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ public class MvxImagePickerTask
private Action<Stream, string> _pictureAvailable;
private Action _assumeCancelled;

#region Event subscriptions

private IDisposable _mediaSubscription;
private IDisposable _imageSubscription;
private IDisposable _cancelledSubscription;

#endregion

private UIImagePickerController EnsurePickerController()
{
if (_picker != null)
Expand All @@ -52,23 +44,16 @@ private UIImagePickerController EnsurePickerController()

private void SubscribeEvents()
{
_mediaSubscription = _picker.WeakSubscribe<UIImagePickerController, UIImagePickerMediaPickedEventArgs>(
nameof(_picker.FinishedPickingMedia), Picker_FinishedPickingMedia);

_imageSubscription = _picker.WeakSubscribe<UIImagePickerController, UIImagePickerImagePickedEventArgs>(
nameof(_picker.FinishedPickingImage), Picker_FinishedPickingImage);

_cancelledSubscription = _picker.WeakSubscribe(nameof(_picker.Canceled), Picker_Canceled);
_picker.FinishedPickingMedia += Picker_FinishedPickingMedia;
_picker.FinishedPickingImage += Picker_FinishedPickingImage;
_picker.Canceled += Picker_Canceled;
}

private void UnsubscribeEvents()
{
_mediaSubscription?.Dispose();
_mediaSubscription = null;
_imageSubscription?.Dispose();
_imageSubscription = null;
_cancelledSubscription?.Dispose();
_cancelledSubscription = null;
_picker.FinishedPickingMedia -= Picker_FinishedPickingMedia;
_picker.FinishedPickingImage -= Picker_FinishedPickingImage;
_picker.Canceled -= Picker_Canceled;
}

public void ChoosePictureFromLibrary(int maxPixelDimension, int percentQuality, Action<Stream, string> pictureAvailable,
Expand Down

0 comments on commit aae2e82

Please sign in to comment.