didReceiveMemoryWarning 建议(后台多任务应用程序太多)?
请帮助,我不知道我与 didReceiveMemoryWarning 到底有什么关系。我的应用程序启动良好,但是当运行的后台应用程序太多时,它会收到内存警告并退出。 我只想显示一个警报,要求用户退出某些后台应用程序。我
有一个appDelegate,在它的窗口中有一个我的viewController的视图,它有另一个分配的视图(复合)和两个子视图(OpenGL 视图上的 XIB),这被设置为 viewController 中的cameraOverlayView。
我试图在警告时将所有内容集中发布,但仍然退出。我是否必须在每个子视图中实现 didReceiveMemoryWarning ?我可以以某种方式“强制退出”初始化过程吗?
Please help, I don't know what I have to do with didReceiveMemoryWarning exactly. My app launched well, but when there is too many running background apps, it receives memory warning, and exit. I just want to show an alert that asks user to exit some background apps.
I have an appDelegate, in its window there is a view of my viewController, it has another view allocated (composite) with two subviews (a XIB over an OpenGL view), and this is set to be a cameraOverlayView in the viewController.
I tried to release the whole stuff in one at warning, but still exited. Do I have to implement didReceiveMemoryWarning in each subview? Can I somehow "forcequit" the initialization process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的应用程序在活动时被终止,则可能存在内存泄漏,导致您的应用程序消耗大量内存。
当操作系统开始耗尽内存时,它将首先终止后台任务,从内存最密集的应用程序开始,然后最终终止最前面的应用程序。用户永远不需要手动终止后台应用程序以节省内存。这一切都是自动完成的。
如果您的应用程序在后台运行,那么它可以随时终止。您能做的最好的事情就是减少总体内存使用量,并希望操作系统在您之前杀死其他一些内存密集型应用程序。
didReceiveMemoryWarning
通常是您释放必须尝试减少应用占用空间的所有缓存数据的地方。应用中视图当前不可见的所有视图控制器都将被卸载,并且viewDidUnload
方法将被调用。您应该在此处将任何IBOutlet
属性设置为 nil。但是,如果您的应用程序在活动时被终止,您应该使用 Instruments 中的 Leaks 工具来确保没有任何泄漏,并且不会消耗异常大量的内存。
If your app is being terminated while it is active, then you probably have a memory leak causing your app to consume a large amount of memory.
When the OS starts running out of memory it will terminate background tasks first starting with the most memory intensive, then eventually the front-most app. The user never needs to manually terminate background apps to save memory. This is all done automatically.
If your app is in the background then it can be terminated at any time. The best you can do is reduce overall memory usage and hope the OS kills some other more memory intensive apps before yours.
didReceiveMemoryWarning
is usually where you would release any cached data you have to try and reduce your app's footprint. Any view controllers in your app whose view isn't currently visible will be unloaded and theviewDidUnload
method will be called. This is where you should set anyIBOutlet
properties to nil.But again if your app is being terminated while it is active, you should use the Leaks tool in Instruments to make sure you don't have any leaks and you aren't consuming an abnormally large amount of memory.