私はこの方法を持っています(他の誰かがそれを書きました!)
- (CGPDFDocumentRef)getPdf {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];
NSURL *pdfURL = [NSURL fileURLWithPath:pdfPath];
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
return pdf;
}
これで、Analyzeを実行して、3つのメモリリーク警告が表示されました。
Call to function 'CGPDFDocumentCreateWithURL' returns a Core Foundation object with a +1 retain count
Object returned to caller as an owning reference (single retain count transferred to caller)
Object leaked: object allocated and stored into 'pdf' is returned from a method whose name ('getPdf') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'. This violates the naming convention rules given in the Memory Management Guide for Cocoa
誰かが私にここで何が必要/何をすべきかを教えてもらえますか?CF関数名にcreateまたはcopyを使用して、すべてをCFReleaseする必要があることを理解しています。私が理解していないのは、PDFをリリースしても、関数の最後でそれを返すことができる方法です。私は何が欠けていますか?ありがとうございました。