开发者

I need help in iphone memory management

I am developing application which is using many photos so definitely it crashes though i released the images as some part is shown in following code

 -(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 objectA开发者_如何学运维tIndex: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 is also not called because i am using tabbased application. So please help how can solve this memory management issue.


The only issue is what you mentioned—that you might have too many images or objects loaded. In that case, you may want to save some data to a file behind the scenes, and do fetches as needed. Maybe instead of storing all the objects in photoArray, write to a file (you could even just write the file path to a file) and batch load ten or so at a time, rather than all of them. Without more info though, there's not much more I can say.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜