NSCollectionViewItem lifecycle
NSCollectionViewItem lifecycle
- Subject: NSCollectionViewItem lifecycle
- From: Andrew Keller <email@hidden>
- Date: Wed, 03 Aug 2016 11:32:38 -0400
Hi all,
I’m experiencing what appears to be some sort of a memory leak with my use of NSCollectionView. I’ve figured out that this problem has actually always been happening ever since I added this particular collection view to the project; I just never noticed because the memory footprint of the array items was so small that it didn’t negatively impact the computer (and I never looked at the memory usage). Well, these days, the data that our users are shoving through the app has grown a lot, to the point where the app now uses about 10 GB of memory after only about 5 minutes. As a temporary workaround, our users can restart the app — but you can imagine how that gets annoying after a while.
So first, some clerical details: this is Xcode 6, on Mac OS X 10.10, using the old-style (pre-10.11) NSCollectionView, with an ArrayController as the data source to the collection view, and using bindings to hook everything up. Nothing is subclassed. The elements of the ArrayController are what I call “Media” objects. The ArrayController’s data source is bound to an NSArray on my window’s controller, and I’m using [myController setMedia:newArray] to change the data. The data is never reordered, and is usually completely swapped out (usually, when I change the content list, it’s a wholesale total rewrite, and none of the objects are ever repeated). The collection view serves to simply display the items visually — not much more than that.
I initially noticed the leak when my computer ran out of memory. Some quick debugging revealed that my Media objects (which have a much larger memory footprint than they used to) are not being deallocated — ever.
According to the memory debugger in Xcode 8 (which is really awesome, by the way), my Media objects are being kept alive by NSCollectionViewItem objects, which also appear to be piling up and never deallocated. The memory debugger also showed me that my view prototype is being created fresh every time — a new one for every cell — every time I set the media array on my controller, and the old cell views are also never deallocated. Not really knowing how NSCollectionView works under the hood, I’m unsure of the next step to troubleshoot this.
Any ideas?
On a related note, what is the expected lifecycle of an NSCollectionViewItem object?
Thanks,
- Andrew Keller
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden