私の最初の投稿は、アプリがクラッシュする理由を探すためにここにあります。検出するのに約 3 時間かかりましたが、今では漏れの場所を見つけることができます。
まず、AFNetworking を使用して画像をダウンロードした後、ダウンロードした画像のサイズに関して uiimageview のサイズを設定します。
[self.headerView setImageWithURLRequest:[NSMutableURLRequest requestWithURL:[NSURL URLWithString:fundraiserInfo.imageUrl]]
placeholderImage:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
// Use following to set the size of image according to retina or non retina
CGImageRef sourceImageRef = [image CGImage];
UIImage *newImage = [UIImage imageWithCGImage:sourceImageRef scale:[image scale] orientation:[image imageOrientation]];
CGImageRelease(sourceImageRef); // <------ this is I am getting crash
weakObj.image = newImage;
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
;
}
];
以下のような警告が表示されます
Incorrect decrement of the reference count of an object that is not owned at this point by the caller
リークを検出する方法:
その行を入力してアプリを実行すると、数回試行した後にアプリがクラッシュします。2 時間後に検出することで、エラーを再現できます。その行を削除し、エラーを再現するために行ったことを正確に実行すると、アプリは正常に実行され、クラッシュすることはまったくありません。
その行が私のアプリをクラッシュさせる理由である理由