Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UICollectionView memory issues #271

Open
AlphaSanets opened this issue Jun 11, 2020 · 18 comments
Open

UICollectionView memory issues #271

AlphaSanets opened this issue Jun 11, 2020 · 18 comments
Assignees
Labels

Comments

@AlphaSanets
Copy link

AlphaSanets commented Jun 11, 2020

If we have a lot of high resolution pictures in the photos, present ImagePickerController and scroll fast - memory usage goes up to 500 MB and even cause crash.
Occurred on IPhone 6+ (iOS 12.4.7).

image
image
image
image

On iPhone XR (iOS 13.5.1) doing the same steps did not occurred the crash but I noticed very high CPU usage (even more than on iPhone 6+). Maybe with the new version of iOS Apple changed work with UICollectionView or PHAsset objects.
Anyway I think it would be nice to implement some sort of cache for UICollectionView.
Possible solutions: here and here.

@mikaoj
Copy link
Owner

mikaoj commented Jun 29, 2020

Awesome dude, I'll check it out!

@mikaoj
Copy link
Owner

mikaoj commented Jul 17, 2020

I'll ping you here so you get notified when it's fixed @sajib-ghoshInnofied

@mikaoj
Copy link
Owner

mikaoj commented Jul 17, 2020

I made some optimization. But it's hard for me to see if it makes a difference, even when profiling, on my iPhone XS running iOS 14.
Sure it consumes 200-300mb of memory when quickly scrolling through tens of thousands of photos but it never becomes a problems as there is lots or free memory.

Could any of you try out commit 974c3fc and compare if it improves things?

@sajib-ghoshInnofied @AlphaSanets

@sajib-ghosh-iOS
Copy link

sajib-ghosh-iOS commented Jul 17, 2020 via email

@mikaoj
Copy link
Owner

mikaoj commented Jul 17, 2020

Hmm. I'm scrolling through 40 000 images (with icloud photos enabled) on my iPhone XS running iOS 14 using the example app included in this repo with zero issues.

How many images are you scrolling through?
What device are you using?
Which iOS version is it running?
Have you done any customization/settings on the image picker? Fetch request, fetch options, cell size, etc?

@sajib-ghosh-iOS
Copy link

sajib-ghosh-iOS commented Jul 17, 2020 via email

@mikaoj
Copy link
Owner

mikaoj commented Jul 17, 2020

It looks like you are using your own fetch options too?

@sajib-ghosh-iOS
Copy link

sajib-ghosh-iOS commented Jul 17, 2020 via email

@mikaoj
Copy link
Owner

mikaoj commented Jul 17, 2020

Still works for me. I'll see if I can dust of an old device running iOS 12 and reproduce it.

Can you clone this repo, checkout the branch feature/performance_optimization and run the example app on your device?
That is what I'm testing with - so we are testing the same app and can rule out that there is something else wrong.

git clone [email protected]:mikaoj/BSImagePicker.git
cd BSImagePicker
git checkout feature/performance_optimization
open BSImagePicker.xcworkspace

@sajib-ghosh-iOS
Copy link

sajib-ghosh-iOS commented Jul 17, 2020 via email

@michelleyin96
Copy link

Re "I think there is some memory leak happening.".

Using the memory graph tool, I also observed that the ImagePickerController is never getting deallocated from memory even after dismiss is called. Tried to look into the implementation a bit and found a few places that weak self was not referenced in closure and tried to fix those but still not fixing the issue.

@sajib-ghosh-iOS
Copy link

sajib-ghosh-iOS commented Jul 18, 2020 via email

@sajib-ghosh-iOS
Copy link

sajib-ghosh-iOS commented Jul 20, 2020 via email

@mikaoj
Copy link
Owner

mikaoj commented Jul 21, 2020

Sort of, I started looking at it and could see high memory usage and sluggish performance on an older device running iOS 12.4. Interestingly it was independent of photos (assets) loading/fetching/viewing but happens even when using vanilla UICollectionViewCells with no asset fetching. But that is something I'll continue looking into whenever I get the time.

The second issue you are mentioning that ImagePickerController isn't deallocated I'm not seeing at all on either device or iOS version. If that is indeed the case I'm guessing that you are keeping a strong reference to it in your code otherwise I'll probably need to see some actual code that can reproduce it.

Also as you seem to be replying using mail, note that none of your attached screenshot can be seen in this issue. Just an FYI :)

@sajib-ghosh-iOS
Copy link

sajib-ghosh-iOS commented Jul 21, 2020 via email

@sajib-ghosh-iOS
Copy link

Hi @mikaoj ,

Did you manage to get time to look into this (High memory issue) issue for older iOS version. This works perfectly for iOS 13.5.1. I think the problem lies in the older version.
It will be very helpful if you resolve this issue and make this awesome library compatible for all versions.

Thanks.

@may-acs
Copy link

may-acs commented Nov 6, 2020

@michelleyin96 were you able to determine if your app was causing the leak? I'm seeing the same issue of ImagePickerController not being deallocated after dismiss. I have combed through my code but can't find the source of the leak.

@tiper
Copy link

tiper commented May 27, 2022

Take a look at my comment here and check if it helps to mitigate the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants