0

縦向きと横向きで異なる画像があり、Document ディレクトリから画像を取得します。合計 62 枚の画像です。サイズが 1015x745 の 31 枚の横向きの画像と、サイズが 751x1024 の縦向きの 31 枚の画像。すべての画像がシミュレーターに読み込まれますが、デバイス内で同じコードを実行すると、アプリケーションがクラッシュします。横長の画像に縦長のみをロードします。

int porWidth = 768, lanWidth = 1024;
int i=0;
    for (CatalogIndividuals *cat in self.array)
    {
        UIImageView *imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(porWidth*i +5, 0, 757, 964)] autorelease];
        imageView1.tag = porImage+i;

        NSString *fullPath =[self.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",cat.portraitImage]];

        imageView1.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:[fullPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"]]];
        imageView1.contentMode = UIViewContentModeScaleAspectFit;

        UIImageView *imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(lanWidth*i +5, 0, 1015, 620)] autorelease];
        imageView2.tag = lanImage+i;

        NSString *tempPath = [self.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",cat.landscapImage]];
        NSString *str = [tempPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];

        NSLog(@"imageView1 fullPath = %@",str);
        imageView2.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:str]];}

メモリリークの問題があると思います。誰かが解決策を持っている場合は助けてください。

4

1 に答える 1

2

これは約 350MB 相当の画像です。メモリリークはありません。メモリを使いすぎているだけです。これはモバイル デバイスであり、デスクトップ コンピューターではありません。使用できるリソースは限られています。

すべての画像を一度にロードするのではなく、コンテンツをスクロールしながら動的にロードする必要があります。Apple が提供するサンプル コードを見て、UIScrollViewタイリングを使用してこれを実現する方法を確認してください。

于 2012-04-24T06:42:24.323 に答える