gpt4 book ai didi

ios - 泄漏 CGImageMergeXMPPropsWhithLegacyProps

转载 作者:行者123 更新时间:2023-11-28 20:33:00 29 4
gpt4 key购买 nike

我正在跟踪我的 iOS 应用程序的内存泄漏,我有一个奇怪的泄漏导致我的应用程序崩溃......负责的框架是:CGImageMergeXMPPropsWhithLegacyProps。在某些时候,我的应用程序收到内存警告 ...

我正在像这样从 ALAsset 创建 UIImage :

    ALAsset *asset = [assetsArray objectAtIndex:index];
UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]];

你知道如何解决这个问题吗?

最佳答案

希望对您有所帮助。我也用了ALAsset,遇到了内存警告。我仍在为我的应用程序搜索我的解决方案...崩溃可能是因为 iOS 由于内存警告而释放了您的 View 或对象。所以,也许防止内存警告很重要。将峰值内存保持在 30MB 以下。我遇到了 ipad2 的 50MB 内存警告,但没有从 iphone4 中获取。无论如何,越低越好。 首先,您可以测量内存通过使用仪器或以下代码。更容易测量代码中的内存以进行日志记录。1.注册一个定时器,用于重复报告内存使用情况,通过这种方式可以看到内存使用峰值。 另一方面,我不知道为什么这个函数会逐渐增加内存。2.《iPhone Programming The Big Nerd Ranch Guide》一书说iOS可能有24MB的图形内存 “过度使用图形内存通常是应用程序收到内存不足警告的原因。Apple 建议您不要使用超过 24 MB 的图形内存。对于图像iPhone屏幕的大小,使用的内存量超过半兆字节。每个 UIView、图像、Core Animation 层以及可以在屏幕上显示的任何其他内容都会占用分配的 24 MB 内存中的一部分。 (对于 NSString 等其他类型的数据,Apple 没有建议任何最大值。)” 因此,查看图形内存使用情况。

NSTimer * timeUpdateTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(reportMem) userInfo:nil repeats:TRUE];
[[NSRunLoop mainRunLoop] addTimer:timeUpdateTimer forMode:NSDefaultRunLoopMode];


-(void) reportMem{
[self report_memory1];
}

-(void) report_memory1 {
struct task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&info,
&size);
natural_t freem =[self get_free_memory];
if( kerr == KERN_SUCCESS ) {
NSLog(@"Memory in use %f %f(free)", info.resident_size/1000000.0,(float)freem/1000000.0);
} else {
NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
}




}


-(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;
}

关于ios - 泄漏 CGImageMergeXMPPropsWhithLegacyProps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11569512/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com