iphone - UIImageView 内存泄漏崩溃问题 - Objective C

标签 iphone ios objective-c memory-leaks uiimageview

我正在尝试使用从服务器加载的图像缩略图来构建我的应用程序。图像数量很大。因此,当我尝试在 iPod 中运行时,它会在加载 50 到 60 张图像后崩溃。崩溃是因为内存泄漏,我通过使用仪器测试我的应用程序得知。我使用了 imageView 和每个 imageView 的按钮,并且我还释放了这些对象。这是我在我的应用程序中使用的代码。

NSInteger result = [self loadedBlipCount] + (_feed.hasMore ? 1 : 0);


if (result == 0 && _emptyFeedCell)
    result = 1;
int outer_count = result/3;


scroll_view.backgroundColor = [UIColor whiteColor];

scroll_view.delegate = self;

for (int i=0; i<outer_count; i++)
//if (i<outer_count)

{
    xPos = 10;

    for (int j=0; j<3; j++) {


        _blipyy = [_feed blipAtIndex:count];


       image_view = [[URLImageView alloc] initWithFrame:CGRectMake(xPos, yPos, 90, 90)];

        image_view.tag = count_tag;
        image_view.url = _blipyy.image_tab_images;



        UIButton *img_butt = [[UIButton alloc] initWithFrame:CGRectMake(xPos, yPos, 90, 90)];
        img_butt.tag = count_tag + 10000;
        [img_butt addTarget:self action:@selector(image_tapped:) forControlEvents:UIControlEventTouchUpInside];

        xPos = xPos + 95;
        count = count + 1;
        count_tag = count_tag + 1;
        //count_1= count_1 +1;

        [scroll_view addSubview:image_view];
        [scroll_view addSubview:img_butt];
        [image_view release];
        [img_butt release];
        //[image_view release];
    }
    // });
    yPos = yPos + 95;

}

请帮我解决这个问题。提前致谢!!

最佳答案

使用 UITableView 代替 ScrollView ,并使用您自己的实现自定义 UITableViewCell 并重新使用单元格。它将在没有任何内存问题的情况下工作。

关于iphone - UIImageView 内存泄漏崩溃问题 - Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14956464/

相关文章:

c# - 使用 ASP.NET 服务器添加 iPhone 推送通知

iphone - iPhone从RSS故障中解析时间

iphone - 带有动画的 popToRootViewController 然后切换选项卡

iphone - UIButton:根据 titleLabel 文本计算 UIButton 的高度

ios - 在PFQueryTableViewController中删除单元格和[self loadObjects]时,它在-[UITableView _endCellAnimationsWithContext:]中出现断言失败。

iphone - 在 Xcode 中重命名或重构文件

iphone - 我想以不同的时间间隔多次调用一个方法

iphone - 为 UIButton 设置一个子类来处理外观

ios - 为什么 UIImageView 不会更改为已设置一次的不同图像?

ios - -[NSString dataUsingEncoding :] gives garbage at end of string in iOS 9, 不是 iOS 8