我需要iphone内存管理方面的帮助



我正在开发使用许多照片的应用程序,因此肯定会崩溃,尽管我发布了图像,因为以下代码中显示了某些部分

 -(void)addScrollView{
[self selectData];

scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(5, 0, 300, 160)];
int counter=10;
float y=10.0f;
int fullLength=[photoArray count];
int horizontal=(fullLength/2)*80;
int vertical=160;
int c1=1;
for(int c=0;c<[photoArray count];c++){
    PhotoData *d=[photoArray objectAtIndex:c];
    //NSLog(d.photoPath);
    if(c==fullLength/2  &&c1<3){
        counter=10;
        y=y+80.0f;
        c1++;
    }
    UIImage *img1=[[UIImage alloc]initWithContentsOfFile:d.photoPath];
    UIButton* button = [[UIButton alloc] init];
    [button setTitle:@"Delete" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    button.tag=d.photoId;
    //set the button states you want the image to show up for
    [button setBackgroundImage:img1 forState:UIControlStateNormal];
    [button setFrame:CGRectMake(counter, y, 70.0, 70.0)];
    //create the touch event target, i am calling the 'productImagePressed' method
    [button addTarget:self action:@selector(deleteImage:)
     forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:button];
    counter=counter+80.0f;
    [img1 release];
    [button release];
}
[scrollView setContentSize:CGSizeMake(horizontal, vertical)];

[self.view addSubview:scrollView];
[scrollView release];
}

Dealloc也没有被调用,因为我使用的是制表应用程序。所以请帮助如何解决这个内存管理问题。

唯一的问题是您提到的—您可能加载了太多的图像或对象。在这种情况下,您可能希望在后台将一些数据保存到一个文件中,并根据需要进行读取。也许不是将所有对象存储在photoArray中,而是写入一个文件(你甚至可以只将文件路径写入一个文件)并一次批量加载10个左右,而不是所有对象。如果没有更多的信息,我就没什么可说的了。

最新更新