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
Fast scrolling with a lot of images causes excessive memory usage #63
Comments
It looks like your collection view cells aren't actually being reused. Try adding an empty dealloc method to PINTestCollectionViewCell and putting a break point in there. It never hits. If the cells aren't being dealloced, then the images aren't either. Eventually this will lead to OOM exception. |
I don't think that's the issue. |
What type of iPad are you testing on? Does it happen with all devices, just at different times? |
Hi @garrettmoon I've tested on an iPad Mini (non retina) on iOS 7 (the one that produced the crash log above) and on an iPad (retina) on iOS 8. It happens on both devices but I don't have a specific time at which this happens, simply after scrolling up and down for about 30 seconds on the mini and about a minute on the iPad (relatively rapidly). |
I'll take a look and see if I can't reproduce it on my local test device and investigate :) |
Ok, so here's the issue, we're not receiving memory warnings. Why? This stack overflow has some explanations: http://stackoverflow.com/a/10009151/262648 It may be that we should set a default memory limit on the PINMemoryCache instance that PINRemoteImage uses and I'd be happy to accept a pull request that had some considered reasoning along with it. In the meantime, you should be able to prevent this issue by setting those limits yourself. Adding this to the application did finish launching method prevented the issue in your test case:
|
Feel free to open this back up if you think there may be another issue going on here. |
The calculation of cost for images stored into the cache could also be improved :) |
Thanks for the quick replies. I'll have a look tomorrow morning. Great stuff 👍 |
Hi @garrettmoon -- I've made the changes (even set the cost limit to 1 image of 1000 * 1000) and I can still reliably reproduce the crash. I'll investigate further and report back. I'm unable to re-open this issue. |
I don't have a low end device to test on, however I'm betting that this has to do with the size of the images being so large and trying to display them all at once. By the way, you'll get huge performance wins if you download images that are the correct size, both in data and scrolling perf. |
Re-opened for you. |
Thanks Garrett. It doesn't necessarily have to be a low-end device. I've managed to get it to crash on an iPhone 6 also. I don't think it has to do with the amount of memory used, but with the speed at which the memory usage increases (e.g. many images decoding at the same time?) which would explain why limiting the memory cache to just one image doesn't cut it either. Yes, having the right image sizes would be the dream! Unfortunately its not yet possible :(. I've not had a chance to look at this properly, but I hope to put some time into it over the weekend. Thanks for your help so far. |
Sure! The speed at which it's decoding the images definitely could be an issue. Here's something to try:
Change that to a small number and see if that addresses the issue (possibly in conjunction with the change in cache size). It's set to NSOperationQueueDefaultMaxConcurrentOperationCount by default. |
Hey @kerrmarin I'm going to close this issue, let me know if you feel it should be reopened. |
Added TTL cache capability
Hi,
I have an iPad app where I show rows of 4 (relatively large: width: 920px; height: 1380px;) images on an iPad inside a collection view. This leads to, when scrolling moderately rapid, excessive memory usage and eventually a crash (on physical devices). An example instruments call tree:
An example of memory usage over time:
Here is a device log from the crash:
I have also created a test project where I can reproduce the issue:
https://github.com/kerrmarin/PINRemoteTest
Is there any way to prevent this crash while maintaining performance? Initially, we thought about setting
PINRemoteImageManagerDownloadOptionsSkipDecode
as one of the options for the manager, but that limits the scroll performance.Thanks
The text was updated successfully, but these errors were encountered: