Ypimagepicker: Memory increases for each use

Created on 4 Oct 2017  路  6Comments  路  Source: Yummypets/YPImagePicker

Before starting the YPImagePicker from my app, I'm around 40MB of used memory (real device).

  • After starting the picker/camera the memory goes up a couple of MBs.
    When I dismiss the picker, the used memory is still at the increased amount.
  • After using filters, the memory goes up around 50MB more.
    When I dismiss the picker, the used memory is still at around 150MB.

So, after opening, using some filters, dismissing a couple of times, the used memory is easily at 500MB.

Can you please look at this?

Bug

Most helpful comment

@theolof
I have found an issue in the example project. The picker's callback was creating a retain cycle so that the picker would still live in memory after being dismissed.
I don't know if you were dismissing the picker that way in your app, but adding [unowed picker] will break this retain cycle and allow for the whole hierarchy to be released (Library / Photo/ Video / Filters ...)

func showPicker() {

    let picker = YPImagePicker()
    picker.showsVideo = true
    picker.videoCompression = AVAssetExportPreset640x480

    // `unowned` is Mandatory since it would create a retain cycle otherwise :)
    picker.didSelectImage = { [unowned picker] img in
        self.imageView.image = img
        picker.dismiss(animated: true, completion: nil)
    }

    present(picker, animated: true, completion: nil)
}

Before 10 subsequent launch would take up around 300MB in memory and with the fix it goes down to around 70MB. (Starting memory being around 70MB)

Let me know if that helps :)

Have a fantastic day!

All 6 comments

@theolof

Thanks for such a detailed explanation.
The picker will always use quite a lot of resources since tapping into the camera library and filters
are memory usages but it should let go of them as soon as it's over.
This looks like an issue then, thanks for the eagle eye !
I am going to look at this into more detail :)

Cheers,

@theolof by the way have you found a way to add the Swedish translations?

@theolof
I have found an issue in the example project. The picker's callback was creating a retain cycle so that the picker would still live in memory after being dismissed.
I don't know if you were dismissing the picker that way in your app, but adding [unowed picker] will break this retain cycle and allow for the whole hierarchy to be released (Library / Photo/ Video / Filters ...)

func showPicker() {

    let picker = YPImagePicker()
    picker.showsVideo = true
    picker.videoCompression = AVAssetExportPreset640x480

    // `unowned` is Mandatory since it would create a retain cycle otherwise :)
    picker.didSelectImage = { [unowned picker] img in
        self.imageView.image = img
        picker.dismiss(animated: true, completion: nil)
    }

    present(picker, animated: true, completion: nil)
}

Before 10 subsequent launch would take up around 300MB in memory and with the fix it goes down to around 70MB. (Starting memory being around 70MB)

Let me know if that helps :)

Have a fantastic day!

@theolof any updates?

Thanks, it fixes the problem.

@theolof Awesome ! Thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pngo-hypewell picture pngo-hypewell  路  7Comments

javiermanzo picture javiermanzo  路  6Comments

fukemy picture fukemy  路  6Comments

twinkalH picture twinkalH  路  4Comments

roarapps picture roarapps  路  4Comments