简体   繁体   English

for-in在循环15K次时消耗太多内存:OS-X应用程序

[英]for-in consuming too much memory while looping for a 15K times: OS-X app

When my loop runs for about 15k times too much memory is consumed. 当我的循环运行大约15k次时,会消耗太多内存。 It's even going beyond 1 GB. 它甚至超过1 GB。 What I am doing inside the loop is a series of Core data entity updating/creation. 我在循环中做的是一系列核心数据实体更新/创建。 Is there any way I could control the memory usage? 有什么办法可以控制内存使用量吗?

Yes, you should use autorelease pools inside your loop. 是的,您应该在循环中使用自动释放池。 Here is the official Apple note about this, and if you use ARC in your project, this answer will be helpful. 以下是苹果官方关于此的说明,如果您在项目中使用ARC, 这个答案将会有所帮助。

使用自动释放池包装循环内容并不时将其耗尽。

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

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