Question

I have a NSCollectionView that I populate using [collectionView setContent:data]; where data is a NSArray filled with objects all of the same custom NSObject subclass. The item prototype of the collection view is a standard NSCollectionViewItem, not subclassed. The collection item's view is populated using bindings from my NSObject subclass.

Now to the problem, when analyzing my app using heapshots I see that there is a huge increase in memory when opening the window with the collection view. Instruments pinpoints this memory increase to the [collectionView setContent:data]; line. This memory is never reclaimed. Any ideas?

EDIT: I access the data object like this:

NSArray *data = [[[[MWWeatherController sharedInstance] cachedData] objectForKey:[NSString stringWithFormat:@"%u",index]] objectForKey:@"daily"];
Was it helpful?

Solution

Have you made the ViewController for the CollectionView KVO compliant?

Has the XIB for the CollectionView an ArrayController?

Bind the CollectionView of the XIB to the arrangedObjects of the ArrayController and set the Items through your ViewController method e.g. setMyCustomObjectsArray, that again sets the array that is observed by the ArrayController.

Make sure you release everything correctly in your custom object's dealloc method too.

OTHER TIPS

I think you are not releasing data in your scope ... if you own the 'data' object make sure you release it.

Some query to answer it better --

  1. How you allocate 'data'?
  2. Who is releasing it?
  3. [collectionView setContent:data]; more code snippet around this line
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top