0

iPhone からクラッシュ ログを取得しました。

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000c
Crashed Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                 0x30011940 objc_msgSend + 20
1   CoreFoundation                  0x30235f1e CFRelease + 98
2   UIKit                           0x308f4974 -[UIImage dealloc] + 36
3   CoreFoundation                  0x30236b72 -[NSObject release] + 28
4   UIKit                           0x30a00298 FlushNamedImage + 64
5   CoreFoundation                  0x30250a20 CFDictionaryApplyFunction + 124
6   UIKit                           0x30a0019c _UISharedImageFlushAll + 196
7   UIKit                           0x30a00730 +[UIImage(UIImageInternal) _flushCacheOnMemoryWarning:] + 8
8   Foundation                      0x3054dc7a _nsnote_callback + 178
9   CoreFoundation                  0x3024ea52 _CFXNotificationPostNotification + 298
10  Foundation                      0x3054b854 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
11  Foundation                      0x3054dbba -[NSNotificationCenter postNotificationName:object:] + 14
12  UIKit                           0x30a00708 -[UIApplication _performMemoryWarning] + 60
13  UIKit                           0x30a006a0 -[UIApplication _receivedMemoryNotification] + 128
14  UIKit                           0x30a005d0 _memoryStatusChanged + 56
15  CoreFoundation                  0x30217410 __CFNotificationCenterDarwinCallBack + 20
16  CoreFoundation                  0x3020d0aa __CFMachPortPerform + 72
17  CoreFoundation                  0x30254a70 CFRunLoopRunSpecific + 2296
18  CoreFoundation                  0x30254164 CFRunLoopRunInMode + 44
19  GraphicsServices                0x3204529c GSEventRunModal + 188
20  UIKit                           0x308f0374 -[UIApplication _run] + 552
21  UIKit                           0x308eea8c UIApplicationMain + 960
...
...

私の前の質問から、iPhone アプリのこのスタックトレースについて誰か手を貸してもらえますか? 、主に UIImage 部分のコードを変更しました。[[UIImage alloc] initWithContentsOfFile ...] を使用しています。[UIImage imageNamed: ... ] などはもうありません。その部分は以下です。

//this is a method of a subclass of UIImageView.
    - (void) reviewImage: (bool) review{
        NSString* st;
        if (review){
        NSString* origin = [NSString stringWithString: [[ReviewCardManager getInstance] getCardImageString:chosenIndex]];
        NSString* stt = [origin substringToIndex: [origin length]-4];

        st = [[NSString alloc] initWithString: stt];

        if (myImageFlipped == nil)
        myImageFlipped = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:@"png"]];
        [self setImage:myImageFlipped];

        if (notRotated){
            self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
            notRotated = false;
        }
    }else{
        st = [[NSString alloc] initWithFormat:@"sc%d", chosenNumber];

        if (myImage == nil)
        myImage = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:@"png"]];

        [self setImage:myImage];

        if (notRotated){
            self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
            notRotated = false;
        }

    }
    [st release];
}

また、UIImage は既にプロパティに保持されています。

@property (nonatomic, retain) UIImage* myImage, *myImageFlipped;

メモリ リークも処理されています。これらの変数は dealloc メソッドで解放されます。

無事にバグを退治できたと思っていたのですが、まだ稀に発生するバグの問題が残っているようです。

クラッシュ ログに基づいて、私のアプリケーションは「performMemoryWarning」と叫びます。サイズが156 x 272の13個の.png画像を「割り当て」ているだけです。混乱しています。これらの画像は、iPhone の RAM を超えるほど多くのメモリを消費するべきではありません。それとも私が見落としているものがありますか?お知らせ下さい。

4

2 に答える 2

0

問題は解決された。ある場所で UIImage を変更するのを忘れていました。現在、すべての UIImage は真に「割り当て」られており、自動解放は行われません。

参考までに、[UIImage imageNamed: ...] を使用している場合は、iPhone シミュレーターで "Simulate Memory Warning" を使用して、実際のデバイスのメモリが不足しているときに問題が発生しているかどうかを確認してください。

于 2009-08-11T15:46:33.423 に答える
0

メモリの問題と UIImages を支援するために、ドキュメントから、UIImage の imageNamed コンビニエンス メソッドを使用することをお勧めします。

This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

または、便利な方法を使用することにはいくつかの欠点があるため、UIImage imageNamed に切り替えた後もメモリの問題が発生する場合は、このルートを使用することをお勧めします。

于 2009-08-10T11:39:47.430 に答える