在我的应用程序运行时的某个(一致)点,我一直收到xcode错误消息
由于内存错误而终止.
我找不到导致错误的代码,但我可以告诉错误附近的代码(使用断点).
在我的实现中返回某个单元格后直接导致错误
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
UITableViewDataSource委托方法.我可以确认它返回有效UITableViewCell,但我认为解释和发布整个方法将浪费你的时间.但是,我怀疑它可能是由快速,大量的内存分配引起的.
它肯定说Terminated due to memory error,而不是记忆压力.
我想知道什么是信息真的意味着什么.另外,有没有办法调试此消息?没有生成崩溃报告.
我正在使用ARC和iOS 7.
我的应用程序由于应用程序使用中某个点的内存压力而终止,我已将问题分解为造成问题的一大块代码.
我将复制下面的代码块,但首先我将描述它正在做什么.
描述:
我有一个迭代视频列表的for循环.对于每个视频,for循环增加包含滚动视图的大小,绘制标签和按钮(均与视频有关),并异步抓取视频的缩略图并将其放在按钮下方.
问题:
抓住缩略图部分就是问题所在.我不认为这是异步完成的事实是问题,因为我已经同步尝试并且终止仍然发生.当我注释掉抓取缩略图的代码(下面代码中的整个异步部分)时,应用程序不会崩溃.
守则:
注意:为简洁起见,我在某些情况下使用注释替换代码.
for (int i = [_videoURLs count]-1; i >= 0 ; i--)
{
//increase the scrollview size
//get background image:
dispatch_async(screenshotQueue, ^{
AVURLAsset *as = [[AVURLAsset alloc] initWithURL:currentURL options:nil];
AVAssetImageGenerator *ima = [[AVAssetImageGenerator alloc] initWithAsset:as];
ima.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 24);
CGImageRef imgRef = [ima copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imgRef];
dispatch_async(dispatch_get_main_queue(), ^{
UIImageView *backgroundImage = [[UIImageView alloc]initWithFrame:buttonFrame];
backgroundImage.image = thumbnail; …Run Code Online (Sandbox Code Playgroud)