首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionViewController:滚动时使用的内存增加

UICollectionViewController:滚动时使用的内存增加
EN

Stack Overflow用户
提问于 2013-10-01 09:17:49
回答 1查看 1.9K关注 0票数 4

我有一个iPhone应用程序显示一个UICollectionViewController。集合视图包含以UILabel作为子视图的单元格。

考虑以下测试代码:

代码语言:javascript
复制
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    UILabel *label = (UILabel *)[cell viewWithTag:1];
    label.text = [NSString stringWithFormat:@"%d", indexPath.row];

    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:    (NSInteger)section
{
    return 500;
}

当我运行应用程序并在集合视图中上下滚动时,XCode 5s调试视图(CMD-6)中显示的内存使用量将稳步增加。这是预期的行为还是我在某个地方泄密了?

接口生成器中的Collection reusable view identifier设置为Cell

编辑:我分析了测试应用程序在仪器,这是一个深刻的副本,似乎增长的调用,同时滚动:

代码语言:javascript
复制
Bytes Used  Count       Symbol Name
   1.01 MB      24.2%   24251       +[NSObject allocWithZone:]
 229.95 KB       5.3%   2774         -[UINibDecoder decodeObjectForKey:]
 173.25 KB       4.0%   2376          -[UIView initWithCoder:]
 111.38 KB       2.6%   1980           -[UICollectionReusableView initWithCoder:]
 111.38 KB       2.6%   1980            -[UICollectionViewCell initWithCoder:]
 111.38 KB       2.6%   1980             -[UINibDecoder decodeObjectForKey:]
 111.38 KB       2.6%   1980              -[UINib instantiateWithOwner:options:]
 111.38 KB       2.6%   1980               -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
 111.38 KB       2.6%   1980                -[UICollectionViewAccessibility(SafeCategory) _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
 111.38 KB       2.6%   1980                 -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:]
 111.38 KB       2.6%   1980                  -[CVTViewController collectionView:cellForItemAtIndexPath:]
 111.38 KB       2.6%   1980                   -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:]
 111.38 KB       2.6%   1980                    -[UICollectionView _updateVisibleCellsNow:]
 111.38 KB       2.6%   1980                     -[UICollectionView layoutSubviews]
 111.38 KB       2.6%   1980                      -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
 111.38 KB       2.6%   1980                       -[NSObject performSelector:withObject:]
 111.38 KB       2.6%   1980                        -[CALayer layoutSublayers]
  61.88 KB       1.4%   396        -[UINibDecoder decodeObjectForKey:]
  61.88 KB       1.4%   396         -[UIView initWithCoder:]
  61.88 KB       1.4%   396          -[UICollectionReusableView initWithCoder:]
  61.88 KB       1.4%   396           -[UICollectionViewCell initWithCoder:]
  61.88 KB       1.4%   396            -[UINibDecoder decodeObjectForKey:]
  61.88 KB       1.4%   396             -[UINib instantiateWithOwner:options:]
  61.88 KB       1.4%   396              -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
  61.88 KB       1.4%   396               -[UICollectionViewAccessibility(SafeCategory) _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
  61.88 KB       1.4%   396                -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:]
  61.88 KB       1.4%   396                 -[CVTViewController collectionView:cellForItemAtIndexPath:]
  61.88 KB       1.4%   396                  -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:]
  61.88 KB       1.4%   396                   -[UICollectionView _updateVisibleCellsNow:]
  61.88 KB       1.4%   396                    -[UICollectionView layoutSubviews]
  61.88 KB       1.4%   396                     -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
  61.88 KB       1.4%   396                      -[NSObject performSelector:withObject:]
  61.88 KB       1.4%   396                       -[CALayer layoutSublayers]
  55.69 KB       1.3%   396       -[UINib instantiateWithOwner:options:]
  55.69 KB       1.3%   396        -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
  55.69 KB       1.3%   396         -[UICollectionViewAccessibility(SafeCategory) _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
  55.69 KB       1.3%   396          -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:]
  55.69 KB       1.3%   396           -[CVTViewController collectionView:cellForItemAtIndexPath:]
  55.69 KB       1.3%   396            -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:]
  55.69 KB       1.3%   396             -[UICollectionView _updateVisibleCellsNow:]
  55.69 KB       1.3%   396              -[UICollectionView layoutSubviews]
  55.69 KB       1.3%   396               -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
  55.69 KB       1.3%   396                -[NSObject performSelector:withObject:]
  55.69 KB       1.3%   396                 -[CALayer layoutSublayers]

(...简称.)

EN

回答 1

Stack Overflow用户

发布于 2013-12-02 12:25:12

看起来,UICollectionViewAccessibility(SafeCategory)中存在某种形式的bug,从而阻止了单元重用的正常工作。

请参阅这个答案以获得更好的解释:UICollectionView do not reuse cells

还有..。发生此问题的设备是什么?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19112347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档