1
votes

I'm using an NSCollectionView (with a custom NSCollectionViewLayout as its layout) to browse potentially thousands of local (on disk) images. What is the best way of ensuring scrolling stays smooth and memory usage (from loading the images to view) doesn't go through the roof?

Currently, each NSCollectionViewItem's representedObject is a class with an NSImage property. I tried making this property optional and loading the image file on viewDidAppear (and setting it as nil on viewWillDisappear) but this stops the images loading at all (viewDidAppear doesn't get called before the parent view is shown?).

All help much appreciated.

1

1 Answers

1
votes

Image caching and image thumbnails are the primary way you can keep memory usage down.

Image caching will keep the number of images in memory at one time to a maximum, this can be accomplished with NSCache or one of the various image caching 3rd party frameworks out there.

Image thumbnails are the conversion of the full sized image into a smaller representation so when you're scrolling you won't be loading in all the data. You can load the full image when you go into a full screen representation.

One other thing is with image misalignment. The general premise is that you want to draw your images into integer-value coordinates, floating point values are harder for GPU computation. (see this SO post)