请帮助iPhone Memory&图像,内存使用崩溃的应用程序

时间:2010-04-27 05:59:52

标签: iphone objective-c memory-management

我遇到与图像有关的内存使用问题,我搜索了文档并观看了来自cs193p和iphone开发站点的视频内存管理和性能。我在网上搜索并在论坛上发帖,但我仍然无法弄明白。

该应用程序使用核心数据,只是让用户将文本与图片相关联,并将项目列表存储在表格视图中,以便您添加和删除项目。单击一行可显示图像和相关文本。就是这样。

在模拟器和设备上一切运行良好。我跑了分析仪它看起来不错,所以我开始看性能。我跑了泄漏,一切都很好看。我的问题是当运行Object Allocations时,每次我选择一行并显示带有图像的视图时,实时字节会跳起几MB并且永远不会下降,我的应用程序最终因内存使用而崩溃。排序实时字节列,我看到2 2.72MB mallocs(总共5.45Mb),14 CFDatas(总共3.58MB),1 2.74MB malloc,其他一切都很小。问题是仪器中的所有相关信息都是技术性的,我所看到的所有解决问题的例子都只是缺少一个版本,并没有什么复杂的。使用[NSSQLCore _prepareResultsFromResultSet:usingFetchPlan:withMatchingRows:]作为除一个以外的所有调用者(fetchResultSetReallocCurrentRow,另一个)的调用程序,仪器显示Core Data作为除一个(libsqlite3.dylib)之外的所有人的负责库,我只是不确定如何追踪问题是什么我查看了堆栈跟踪并打开了我的代码的最后一个实例,发现了2个罪魁祸首(下图)。我根本没有得到任何回复,所以如果有人有任何提示或指示,我真的很感激!!!!

    //this is from view controller that shows the title and image
    - (void)viewWillAppear:(BOOL)animated 
    {
        [super viewWillAppear:animated];
    self.title = item.title;
    self.itemTitleTextField.text = item.title;
    if ([item.notes length] == 0) 
    {
        self.itemNotesTextView.hidden = YES;
    } else 
    {
        self.itemNotesTextView.text = item.notes;
    } //this is the line instruments points to
    UIImage *image = item.photo.image;
    itemPhoto.image = image;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
        // Delete the managed object for the given index path
        NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
        [context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];

        // Save the context.
        NSError *error = nil;
        if (![context save:&error]) //this is the line instruments points to
        {

            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            exit(-1);
        }
    }   
}

1 个答案:

答案 0 :(得分:0)

我建议您存储图片网址而不是图片数据本身。这可以防止CoreData使用和缓存大数据。