2010-04-07 2 views
1

누군가 내가 여기서 잘못하고있는 것을 말해 줄 수 있습니까? 이 방법을 사용하여 PDF의 페이지를 뒤집습니다. 하지만 코드에서 뭔가가 제대로 풀리지 않는 것 같습니다. 매번 메모리 공간이 증가하는 이미지가 포함 된 PDF 페이지를 가져 오기 때문입니다. CoreGraphics를 처음 접했을 때,이 방법으로 메모리가 누출 될 수있는 곳을 찾아 낼 수 없었습니다.iPhone : CoreGraphics 및 메모리 관리

-(UIImage *)pageAtIndex:(NSInteger)pageNumber withWidth:(CGFloat)width andHeight:(CGFloat)height { 
    if((pageNumber>0) && (pageNumber<=pageCount)) { 
     CGFloat scaleRatio; // multiplier by which the PDF Page will be scaled 

     UIGraphicsBeginImageContext(CGSizeMake(width, height)); 
     CGContextRef context = UIGraphicsGetCurrentContext(); 
     CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber); 
     CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFBleedBox); 

     //Figure out the orientation of the PDF page and set the scaleRatio accordingly 
     if(pageRect.size.width/pageRect.size.height < 1.0) { 
      scaleRatio = height/pageRect.size.height; 
     } 
     else { 
      scaleRatio = width/pageRect.size.width;  
     } 

     //Calculate the offset to center the image 
     CGFloat xOffset = 0.0; 
     CGFloat yOffset = height; 
     if(pageRect.size.width*scaleRatio<width) { 
      xOffset = (width/2)-(pageRect.size.width*scaleRatio/2); 
     } 
     else { 
      yOffset = height-((height/2)-(pageRect.size.height*scaleRatio/2)); 
     } 
     CGContextTranslateCTM(context, xOffset, yOffset); 
     CGContextScaleCTM(context, 1.0, -1.0); 
     CGContextSaveGState(context); 
     CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFBleedBox, CGRectMake(0, 0, pageRect.size.width, pageRect.size.height), 0, true); 
     pdfTransform = CGAffineTransformScale(pdfTransform, scaleRatio, scaleRatio); 

     CGContextConcatCTM(context, pdfTransform); 
     CGContextDrawPDFPage(context, page); 

     UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext(); 

     CGContextRestoreGState(context); 
     UIGraphicsEndPDFContext(); 
     UIGraphicsEndImageContext(); 

     return tempImage; 
    } 
    return nil; 
} 

답변

1

사과 코어 그래픽 메일 링리스트의 사람들에게 문제가 해결 된 것 같습니다. CGPDFDocument는 호출간에 데이터를 캐시하지만 절대로 해제하지 않는 것 같습니다. 이것은 CoreGraphics의 버그 인 것 같습니다. 이 문제를 해결할 수있는 유일한 방법은 페이지를 가져올 때마다 PDF를로드하고 언로드하는 것입니다.

+0

레이더에 제출 했습니까? – Sneakyness

+0

고마워요. 그것이 아직 고쳐 졌는지 알 수 있습니까? –

1

아마도 뭔가를 공개하지 않았을 것입니다. CGPDFPageRetain(<CGPDFPageRef page>)CGPDFPageRelease(<CGPDFPageRef page>)과 같은 항목을 확인하십시오.