NSCollectionView的setContent:内存管理
我有一个 NSCollectionView
,我使用 [collectionView setContent:data];
填充,其中 data
是一个 NSArray
填充所有相同的自定义 NSObject
子类的对象。集合视图的项目原型是标准的 NSCollectionViewItem
,而不是子类。集合项的视图是使用我的 NSObject
子类中的绑定填充的。
现在问题来了,当使用堆快照分析我的应用程序时,我发现使用集合视图打开窗口时内存会大幅增加。 Instruments 将内存增加精确定位到 [collectionView setContent:data];
行。该记忆永远不会被回收。有什么想法吗?
编辑:我像这样访问数据对象:
NSArray *data = [[[[MWWeatherController sharedInstance] cachedData] objectForKey:[NSString stringWithFormat:@"%u",index]] objectForKey:@"daily"];
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"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否使 CollectionView KVO 的 ViewController 兼容?
CollectionView 的 XIB 有 ArrayController 吗?
将 XIB 的 CollectionView 绑定到 ArrayController 的排列对象,并通过 ViewController 方法设置项目,例如 setMyCustomObjectsArray,这再次设置 ArrayController 观察到的数组。
确保您在自定义对象的 dealloc 方法中也正确释放了所有内容。
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.
我认为您没有在您的范围内释放数据......如果您拥有“数据”对象,请确保释放它。
一些问题可以更好地回答它——
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 --