私の質問は非常に簡単ですが、"CGImageSourceCreateWithData"が私が提供するデータをコピーする新しいオブジェクトを作成して、私がもうそれを必要としないときにリリースする必要があるかどうか、すでにデータを参照していますので、リリースすればこのデータは失われてしまいます(おそらく不正なアクセスエラーが発生する可能性があります)。(__bridge)からCGImageSourceCreateWithDataを使用している場合は、「CFRelease」が必要ですか?
問題は、(__bridge CFDataRef)をソースデータとして使用することに関連しています。 ARCモードでCore Foundationオブジェクトをフリーダイヤルとして使用しています。
- (void)saveImageWithData:(NSData*)jpeg andDictionary:(NSDictionary*)dicRef andName:(NSString*)name
{
[self setCapturedImageName:name];
CGImageSourceRef source ;
// Notice here how I use __bridge
source = CGImageSourceCreateWithData((__bridge CFDataRef)jpeg, NULL);
CFStringRef UTI = CGImageSourceGetType(source);
NSMutableData *dest_data = [NSMutableData data];
// And here I use it again
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data,UTI,1,NULL);
CGImageDestinationAddImageFromSource(destination,source,0, (__bridge CFDictionaryRef) dicRef);
BOOL success = NO;
success = CGImageDestinationFinalize(destination);
if(!success) {
NSLog(@"***Could not create data from image destination ***");
}
// This only saves to the disk
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"ARPictures"];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
NSString *fullPath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", name]]; //add our image to the path
[dest_data writeToFile:fullPath atomically:YES];
self.img = [[UIImage alloc] initWithData:dest_data];
self.capturedImageData = [[NSData alloc] initWithData:dest_data];
//This is what im not sure if i should use
CFRelease(destination);
CFRelease(source);
}
私の関心は、メモリリークや、私がいけないdealocatingの事についてです:
は、次の関数(またはメソッド、それが呼ばれていますかどうかはわかりませんが)考えてみましょう。
ありがとうございました
私は、基本的に私は常に私はいつも右にリリースする必要があります参照してください参照してください?私はこのコードを最適化したいので混乱していました。これらの余分な2つのコピーを持たないように、それらを直接ブリッジするココアオブジェクトを使用する可能性を検討していました。今すぐに私は元のデータ(jpegデータが入ってくる)、ソースと宛先、さらには最後の2つのプロセスがメモリを大量に消費するように見えることがあります。これはできますか? btw ur高速返信ありがとう – Pochi
名前にCreateまたはCopyが含まれているメソッドとCFReleaseとのバランスをとる必要があります。残りの部分については、ここでCore Graphicsを使用している理由はわかりません。 'imageWithData:'でJPEGデータをUIImageに変換することができます。もっと複雑なことをしていますか? –
ええ、私はいくつかの追加情報を追加して画像のメタデータを変更しています。だから私はこれがデータを変更する唯一の方法だと思っていました。 – Pochi