Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leaks when Scanner.h is used from an ARC file #80

Open
leifhanson opened this issue Dec 15, 2014 · 0 comments
Open

Memory Leaks when Scanner.h is used from an ARC file #80

leifhanson opened this issue Dec 15, 2014 · 0 comments

Comments

@leifhanson
Copy link

Hello KurtCode and GitHub,
I have been working to leverage PDFKitten as a search for a project primarily using VFR Reader as it's PDF Viewer. I have been able to add the -fno-objc-arc flag to all the PDFKitten files to get them to build.
I'm using PDFKitten to search through the PDF and report if each page has a search term like so:
(Note: document is an instance of the VFR Reader ReaderDocument class)

#import "Scanner.h"
// Search Document and create Array that holds how many hits per page.
NSInteger intPageCount = [pageCount integerValue];
NSInteger i = 1;
CGPDFDocumentRef thePDFDocRef = CGPDFDocumentCreateUsingUrl((__bridge CFURLRef)(document.fileURL), document.password);

 for(i = 1; i < intPageCount; i++) {
    CGPDFPageRef searchPage =  CGPDFDocumentGetPage(thePDFDocRef, i);
    NSString *currentSearch = searchBar.text;

    Scanner *scanner = [Scanner scannerWithPage:searchPage];
    NSArray *selections = [scanner select:currentSearch];

    // Send the results of the search to the searchMarked NSMutable Array.
    if(selections.count > 0) {
        NSNumber *searchPageHit = [NSNumber numberWithInteger:i];
        [searchmarked addObject:searchPageHit];
    }
}

This code works, returning me an array of page numbers that contain my search term. However, every time I search quite a bit more ram is taken up. I suspect this is because I am instantiating the Scanner class from within a class using ARC, but the Scanner class itself uses MRC.

Here is output from Leaks after one successful search:
leaks_screenshot

I have tried to convert PDFKitten to use ARC, and I'm afraid I'm just a littler too new with iOS to pull this off. I have also tried setting scanner to nil after it is used in every pass of the for loop, but it doesn't seem to make any difference. In addition, I have tried wrapping the for loop around an autorelease pool, and that didn't work either.

I will continue work, but any help would be greatly appreciated.

Thankyou KurtCode and GitHub community in advance for any advice or help you can offer.

Update: I have just noticed a pull request by user tarunbatta that has ARC fixes for PDFKitten. I will implement these to my PDFKitten base this evening and report back to this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant