简体   繁体   English

可可不在后台释放内存

[英]Cocoa not releasing memory in background

I have an object that allocates memory during its init and releases it during dealloc. 我有一个在初始化期间分配内存并在dealloc期间释放内存的对象。 When my app is in the background, and these objects are created/released, according to Activity Monitor, the memory is allocated but not released. 根据活动监视器,当我的应用程序在后台运行并且创建/释放了这些对象时,内存已分配但未释放。 Only when I click my app to bring it into the foreground is the memory freed. 只有当我单击我的应用程序使其进入前台时,才释放内存。

This is a problem as my app is designed to run in the background. 这是一个问题,因为我的应用程序旨在在后台运行。

Any ideas on how to fix this? 有想法该怎么解决这个吗?

Two things comes to mind here... 这里有两件事要想到...

  1. The app has marked the object to free() the memory allocation. 该应用已将对象标记为free()内存分配。 This will happen in the loop whenever the system see fits (since its running in the background). 只要系统认为合适,就会在循环中发生(因为它在后台运行)。

  2. Some object is still holding a reference to the allocation and doesn't release this reference until you bring the app to the foreground again. 某些对象仍然持有对该分配的引用,并且直到您再次将该应用程序置于前台,才释放该引用。

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

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