Why is my customer filter leaking memory on iOS?

19 views
Skip to first unread message

James

unread,
Feb 23, 2017, 3:11:26 PM2/23/17
to PDFTron PDFNet SDK
Q:

The app I’m working on need to be able to read PDF files using an homemade encryption system. PTFilter seems to fit my needs.

Everything is working just fine except the fact that, for some reason, my use of PDFNet is not memory efficient at all.
Scrolling through a big file full of images make the memory grow until there is no space left, resulting to a crash.

---------------------------------------------------------

A:

You can correct the behaviour by placing the creation of the autoreleased NSData object in its own autorelease pool:

static size_t filter_read (void* buf, size_t sz, size_t count, void* user_data) {
    @autoreleasepool {
        NSData* data = [((__bridge Filter*)user_data) readDataOfLength:sz*count];
        [data getBytes:buf length:data.length];
        return data.length/sz;
    }
}

Doing so is necessary because the method is called on a secondary, platform-independent POSIX thread that does not come with its own top-level autorelease pool. This is true of all callbacks declared in a C (as opposed to Objective-C) header.
Reply all
Reply to author
Forward
0 new messages