iPhone 应用程序在内存警告事件发生前崩溃

发布于 2024-12-01 12:34:57 字数 183 浏览 5 评论 0原文

应用程序因内存开销而崩溃,但 applicationDidReceiveMemoryWarning 事件未及时引发。 (我确切地知道崩溃的原因是内存不足,因为它在资源加载时崩溃并且没有相应的崩溃报告,并且XCode不会中断调试,应用程序默默地退出到跳板)。

所以我正在寻找一些方法来防止这种开销。也许有一个函数或工具可以提供可用内存量?

The app crashes because of memory overhead, but applicationDidReceiveMemoryWarning event doesn't raise in time. (I know exactly that the reason of crash is low memory because it crashes on resources loading and there is no corresponding crash report, and XCode doesn't break debugging, app silently quits to springboard).

So I'm looking for some method how to prevent this overhead. Maybe there is a function or instrument that gives amount of available memory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

城歌 2024-12-08 12:34:57

在仪器(分配)中运行它并捕获前后堆的快照。

Run it in instruments (allocations) and capture a shot of the heap before and after.

原野 2024-12-08 12:34:57

罗伯特·哈维链接中的答案:

#import <mach/mach.h>
#import <mach/mach_host.h>

+(natural_t) get_free_memory {
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
NSLog(@"Failed to fetch vm statistics");
return 0;
}
/* Stats in bytes */
natural_t mem_free = vm_stat.free_count * pagesize;
return mem_free;
}

The answer in link by Robert Harvey:

#import <mach/mach.h>
#import <mach/mach_host.h>

+(natural_t) get_free_memory {
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
NSLog(@"Failed to fetch vm statistics");
return 0;
}
/* Stats in bytes */
natural_t mem_free = vm_stat.free_count * pagesize;
return mem_free;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文