应用扩展“因内存问题而终止" [英] App Extension "Terminated due to memory issue"

查看:83
本文介绍了应用扩展“因内存问题而终止"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序通知服务扩展中,我执行以下操作:- 从 Parse 获取数据(在后台),- 将数据写入文件- 将数据保存在 NSUserDefaults 中(在共享容器中).

In my app Notification Service Extension I do the following things: - get data (in background) from Parse, - write data to file - save data in NSUserDefaults (in a shared container).

有时我会收到消息:由于内存问题而终止".没有关于导致这种情况的原因的其他信息.

Sometimes I get the message: "Terminated due to memory issue". No other information about what causes this.

有人有这方面的经验吗?奇怪的是,它只是偶尔发生.

Anybody experience with this? This strange thing is that it only happens now and then.

推荐答案

通知服务扩展存在内存限制.您应该使用小于约 4.5M 的内存.所以避免使用 NSUserDefaults.并尽量节省您使用的内存.

There is a memory limit in notification service extension. You are supposed to use memory less than about 4.5M. So avoid using NSUserDefaults. And Try to save memory you use.

今天刚学会.NSUserDefaults 存储为属性列表文件.并且当您从属性列表中读取单个值时,整个属性列表会立即反序列化,从而导致内存使用量迅速增加.我认为这就是为什么从通知服务扩展中的 NSUserDefaults 读取值会导致内存问题.

Just learned this today. NSUserDefaults is stored as property list files. And when you read single value from a property list, the whole property list is deserialized at once, causing rapid increasing in memory using. I think that's why reading values from NSUserDefaults in notification service extension causes memory problem.

这篇关于应用扩展“因内存问题而终止"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆