KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to create previews images of pages in a PDF but I have some problems with the release of memory. I wrote a simple test algorithm that cycles on the problem, the app crashes near the 40th iteration : NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myPdf.pdf"]; CFURLRef url = CFURLCreateWithFileSystemPath( NULL, (CFStringRef)pdfPath, kCFURLPOSIXPathStyle, NO ); CGPDFDocumentRef myPdf = CGPDFDocumentCreateWithURL( url ); CFRelease (url); CGPDFPageRef page = CGPDFDocumentGetPage( myPdf, 1 ); int i=0; while(i < 1000){ UIGraphicsBeginImageContext(CGSizeMake(768,1024)); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0); CGContextFillRect(context,CGRectMake(0, 0, 768, 1024)); CGContextSaveGState(context); CGContextTranslateCTM(context, 0.0, 1024); CGContextScaleCTM(context, 1.0, -1.0); CGContextDrawPDFPage(context, page); CGContextRestoreGState(context); // -------------------------- // The problem is here (without this line the application doesn't crash) UIImageView *backgroundImageView1 = [[UIImageView alloc] initWithImage:UIGraphicsGetImageFromCurrentImageContext()]; // -------------------------- UIGraphicsEndImageContext(); [backgroundImageView1 release]; NSLog(@"Loop: %d", i++); } CGPDFDocumentRelease(myPdf); The above-mentioned line seems to generate a memory leak, however, instruments doesn't show memory problems; Can I escape from this kind of mistake?someone can explain me in which way? Are there other ways to show previews of a pdf? UPDATE I think the problem isn't the release of UIImage created by the method UIGraphicsGetIm
Tags (comma-separated)
Save Edits
Cancel