2012-05-04 1 views
0

画像ギャラリーとサムネイルギャラリーでたくさんの画像を読み込みます。ボタン(セクション)を押すたびに、画像が正しいseciontの画像で置き換えられます。 7回私はこれを私のアプリケーションのクラッシュを行う。 私は割り振りツールを使ってビルドを試みましたが、私はボタンを押すたびに割り当てメモリが増えていくのを見ています!私は initWithContentOfFileで成長していないスタックメモリの割り当てを見ることができます。 何が間違っていますか?UIImagaViewのXcode割り当てに関する問題が増え続けています

for (UIView *view in [scroller subviews]) { 

    [view removeFromSuperview]; 


} 
for (UIView *view in [thumbnail subviews]) { 

    [view removeFromSuperview]; 


} 


for (int i=1; i<numeroimg+1; i++) { 
    UIImageView *imagen = [[[UIImageView alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile: 
                   [[NSBundle mainBundle] 
                   pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i] 
                   ofType:@"jpg"]]]autorelease]; 
    imagen.frame = CGRectMake((i-1)*1024, 0, 1024, 704); 

    [scroller addSubview:imagen]; 

    UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake((i-1)*210, 30, 200, 150)]autorelease]; 
    [button setImage:[[UIImage alloc] initWithContentsOfFile: 
         [[NSBundle mainBundle] 
         pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i] 
         ofType:@"jpg"]] forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(pagina:) forControlEvents:UIControlEventTouchUpInside]; 
    button.tag = i; 
    [thumbnail addSubview:button]; 
} 
+0

を排出するようにしてください、あなたは、ARCを使用していますか? – Michael

+0

nopは古いバージョンのxcodeで作業を開始しなければならなかったので、それを置くことができません – Yazo

+0

プロジェクトをARCに変換すると、WWDC 2011のビデオがあります。 – Michael

答えて

0

私は間違っていますか?あなたがイメージを作成する+allocを使用している

UIImageView *imagen = [[[UIImageView alloc] initWithImage:... 

いますが、imagenを解放することはありません。

+0

私はautoreleaseを削除して[imagen release]を追加しても、 [ボタンリリース]それはまだ成長している – Yazo

0

は、手動で自動解放プール

@autoreleasepool{ 
UIImageView *imagen = [[[UIImageView alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile: 
                   [[NSBundle mainBundle] 
                   pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i] 
                   ofType:@"jpg"]]]autorelease]; 
    imagen.frame = CGRectMake((i-1)*1024, 0, 1024, 704); 

    [scroller addSubview:imagen]; 

    UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake((i-1)*210, 30, 200, 150)]autorelease]; 
    [button setImage:[[UIImage alloc] initWithContentsOfFile: 
         [[NSBundle mainBundle] 
         pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i] 
         ofType:@"jpg"]] forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(pagina:) forControlEvents:UIControlEventTouchUpInside]; 
    button.tag = i; 
    [thumbnail addSubview:button]; 
} 
関連する問題