简体   繁体   English

如何减少ios应用程序中的内存使用量?

[英]How can i reduce memory usage in my ios app?

I am building a Pinterest like app, which has a uicollectionview with endless cells, each having an image. 我正在构建一个类似Pinterest的应用程序,该应用程序的uicollectionview包含无尽的单元格,每个单元格都有一个图像。

Now continually scrolling through the collectionview, more images are loaded and cached. 现在,连续滚动浏览collectionview,将加载和缓存更多图像。

I am observing that the memory usage is reaching 200MB and increasing. 我观察到内存使用量已达到200MB,并且还在增加。

My question is what are the best practices used in this case ? 我的问题是在这种情况下使用的最佳实践是什么?

One important thing is to reuse your cell. 重要的一件事是重用您的单元。 You can reference to the following method. 您可以参考以下方法。

func dequeueReusableCell(withReuseIdentifier identifier: String, 
                     for indexPath: IndexPath) -> UICollectionViewCell

https://developer.apple.com/documentation/uikit/uicollectionview/1618063-dequeuereusablecell https://developer.apple.com/documentation/uikit/uicollectionview/1618063-dequeuereusablecell

Call this method from your data source object when asked to provide a new cell for the collection view. 当要求为集合视图提供新的单元格时,请从数据源对象中调用此方法。 This method dequeues an existing cell if one is available or creates a new one based on the class or nib file you previously registered. 如果有一个可用的单元格,此方法将使该单元出队,或者根据您先前注册的类或nib文件创建一个新的单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM