3
我有一個顯示UICollectionViewController的iPhone應用程序。集合視圖包含具有UILabel作爲子視圖的單元格。UICollectionViewController:滾動時使用的內存增加
考慮以下測試代碼:
- (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)中顯示的存儲器使用量將穩步增加。這是預期的行爲還是我有泄漏的地方?
Interface Builder中的Collection reusable view identifier
設置爲Cell
。
編輯: 我異形在儀器的測試程序,這是調用的深層副本,似乎在滾動時長:
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]
(... ...縮寫)
它不停止一些上限? – micantox
不是我能看到的。從上到下滾動並返回幾分鐘,內存使用增長緩慢但穩定。 – Cornelius
儀器..... –