Search code examples
iosswiftuicollectionviewuicollectionviewcelltvos

When is the memory allocated for UICollectionViewCell rasterizations freed?


So, in my app I have a bunch of view controllers that use UICollectionView as their main structure. These contain cells composed of an image and some overlay text and there are a potentially large number of these cells that will be created throughout the course of navigating the app (well into the hundreds and possibly 1000+. It's a huge catalog of content). I've found the enabling rasterization:

cell.layer.shouldRasterize = true
cell.layer.rasterizationScale = UIScreen.mainScreen().scale

drastically speeds up performance, making the framerate go from ~31fps to ~58fps, but, as expected, the memory for the app steadily increases.

So my question is when are these cached rasterized images removed? Is it only when the app is stopped? Or is it when the views containing them are deinit? Is there a way to manually force them to be removed if it's the former?


Solution

  • enter image description hereThe cached layers are removed if unused for 100ms.

    Here are important notes from WWDC 2014

    • The image is composited on the GPU
    • Cache size is limited to 2.5x of screen size

    http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_advanced_graphics_and_animation_performance.pdf