I am implementing a pdf reader.The way i am writing code is sufficient for many pdf's suddenly one single pdf came into picture with 300MB(total 1000 pages).The pdf is working fine up to 70 pages later it is killing my application i am checking in the divice(IPad1,V5.0) and simulator(V 5.0).In simulator i can navigate with all pages from starts at 1 till the last page but coming to device i cant do that.I seen memory allocation in the "Instruments tool"
On the image rectangle box showing me memory allocation and fluctuating of the memory utilization,for each single page newly rendered(first time after opening the app) CGContextDrawPDFPage method increasing 2MB of memory.I dont know why CGContextDrawPDFPage increasing drastically.I seen many blogs on this but there is no use and waste of time.Below is my sample code
otherPageRef = CGPDFDocumentGetPage(myDocumentRef, c);
cropBox = CGPDFPageGetBoxRect(otherPageRef, kCGPDFCropBox);
CGContextSaveGState(ctx);
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(ctx,CGContextGetClipBoundingBox(ctx));
CGFloat aspectRatio=aspectFitSize.width/aspectFitSize.height;
CGRect targetRect = layer.bounds;
CGFloat xScale = targetRect.size.width / cropBox.size.width;
CGFloat yScale = (targetRect.size.height-__TOP_BRANDING_BAR_HEIGHT) / cropBox.size.height;
CGFloat scaleToApply = (xScale < yScale) ? xScale : yScale;
CGContextTranslateCTM(ctx, -cropBox.origin.x, layer.bounds.size.height- __TOP_BRANDING_BAR_HEIGHT +cropBox.origin.y);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGAffineTransformMakeScale(scaleToApply, scaleToApply));
if (scaleToApply == yScale){
CGContextConcatCTM(ctx, CGAffineTransformMakeTranslation((layer.bounds.size.width-(cropBox.size.width*scaleToApply)-cropBox.origin.x)/(scaleToApply * 2.0), 0));
}
else{
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
CGContextConcatCTM(ctx, CGAffineTransformMakeTranslation(0, (layer.bounds.size.height- __TOP_BRANDING_BAR_HEIGHT -(cropBox.size.height*scaleToApply))/(scaleToApply*2.0)));
}
else {
CGContextConcatCTM(ctx, CGAffineTransformMakeTranslation(0, (layer.bounds.size.height- __TOP_BRANDING_BAR_HEIGHT -(cropBox.size.height*scaleToApply))/(scaleToApply*2.0)));
}
}
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx, otherPageRef);
CGContextRestoreGState(ctx);
can any one guess what is the cause for my app crashing and please suggest me to handling technique.I even tried my cgpdfdocumentRef releasing and retaining method but no use.Your suggestion is more useful for me.Thanks in advance.