内存崩溃前未调用 didReceiveMemoryWarning
当我的应用程序第一次加载时,我正在加载几个大的 csv 文件,这在模拟器上运行良好,但在我的手机上运行时,它崩溃了大约 30%,并显示消息“程序收到信号“0””,这意味着内存崩溃。但是,当我在 didReceiveMemoryWarning 事件中放置断点时,它似乎没有被调用。
我是否遗漏了任何内容,或者程序会在没有调用事件的情况下正常关闭吗?
I'm loading a couple of large csv files when my app loads for the first time and this works fine on the simulator but when running on my phone it crashes about 30% through with the message 'Program received signal "0"' which implies a memory crash. However, when I put a breakpoint in the didReceiveMemoryWarning event it doesn't seem to be called.
Am I missing anything or will the program normally shut down without the event being called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在应用程序主线程上的同步调用中加载文件,这将阻止它在同步调用完成之前接收其他消息(例如内存警告)。尝试将加载 CSV 文件设为异步任务。 (一个好的起点是阅读
NSOperation
。)这将允许您的应用程序在加载过程中接收内存警告。If you're loading the file in a synchronous call on your app's main thread, that would prevent it from receiving other messages (such as memory warnings) before the synchronous call completes. Try making loading the CSV files an asynchronous task. (A good starting point would be reading up on
NSOperation
.) That will allow your app to receive memory warnings during the loading process.如果您尝试加载小 csv 会发生什么。如果工作正常,那么您的 csv 太大并导致内存问题。如果是这样,您可能必须逐块读取 csv 文件,并在读取新文件之前释放旧文件的内存。
What's happen if you try loading small csv instead. If it work fine then your csv is too large and cause memory issue. If so you may have to read the csv file chunk by chunk and release the memory of the old one before reading the new one.