开发者

iOS Core Graphics PDF memory managment problem

I'm reading PDF file, and then releasing it:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)@"somepdf.pdf", NULL, NULL);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);    
int pagesCount = CGPDFDocumentGetNumberOfPages(pdf);
CGPDFDocumentRelease(pdf);

But the memory is not freed after release (checked that with Instruments). Why? What i'm missing in memory managment.

Thanks.

EDIT

here is my code:

- (void)loadView {
            [super loadView];
 开发者_运维技巧           CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)@"some.pdf", NULL, NULL);
            pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); 
            CFRelease(pdfURL);
            CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdf, 1);

            TiledPDFView * v = [[TiledPDFView alloc] initWithFrame:self.view.bounds andScale:1];
            [v setPage:pdfPage];

            [self.view addSubview:v];


            UIButton * but = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [but setTitle:@"removeView" forState:UIControlStateNormal];
            [but addTarget:self action:@selector(tests) forControlEvents:UIControlEventTouchDown];
            but.frame = CGRectMake(0, 0, 100, 40);
            [self.view addSubview:but];

    }

    -(void) tests {
        [self.view removeFromSuperview];
        [self.view release];
        CGPDFDocumentRelease(pdf);
    }

pdf is instance variable. TiledPDFView - is uiview from ZoomingPDFViewer example. it draws CGPDFPageRef using CATiledLayer.

after i call tests method, the view is removed (becomes invisible), but the memory allocated with CGPDFDocumentCreateWithURL is not freed.


What memory is not released? As you say, you duly released the CGPDFDocument, so that should have gone away.

Are you sure it's not the CFURL that's sticking around? You don't show yourself releasing that, but you Copied it, so you are obliged to. See the Memory Management Guide for Core Foundation.

You can use the ObjectAlloc instrument to determine which specific objects are remaining alive. Set the beginning and end points in the timeline to before the object was created and after it was freed, respectively, then set the instrument to show you “Objects Created & Still Living”. You can also use the Leaks instrument to show you what objects are still living that you no longer have a pointer to. Both instruments initially show a breakdown by class, into which you can drill down to instances and then events (allocations, retentions, autoreleases, releases, and deallocations).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜