附录一制造了新的read子,并穿过物体。 如何释放?
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
float x= scrollView.contentOffset.x/(self.view.frame.size.width/2 + 40 );
int pg=round(x);
pg=abs(x);
currentPage=pg;
if(pg!=currentIndex && pg+1 < pageCounter)
{
currentIndex= pg;
NSNumber *num=[NSNumber numberWithInt:pg+1];
[NSThread detachNewThreadSelector:@selector(getImageForPage:) toTarget:self withObject:num];
}
}
工作背景
-(void)getImageForPage:(NSNumber*)page{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
int pg=[page intValue];
UIButton *btn = (UIButton*)[scrl viewWithTag:pg];
UIImageView *imgV = (UIImageView *)[btn viewWithTag:1111];
if(imgV.image==nil)
{
NSLog(@"currnt visible page %d ",currentPage);
if(!isWorking)
{
UIImage *im= [self imageFromPDFforPage:pg+1];
imgV.image = im;
}
else
[self performSelector:@selector(getImageForPage:) withObject:[NSNumber numberWithInt:pg+1] afterDelay:3];
}
[pool drain];
}
我应称[集合排水];或 [集合释放];
- (UIImage *)imageFromPDFforPage:(int)page {
isWorking=YES;
CGPDFPageRef pageRef = CGPDFDocumentGetPage(pdf, page);
CGRect pageRect = CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox);
NSLog(@"page %d, w= %f h= %f",page, pageRect.size.width,pageRect.size.height);
UIGraphicsBeginImageContext(pageRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, CGRectGetMinX(pageRect),CGRectGetMaxY(pageRect));
CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, -(pageRect.origin.x), -(pageRect.origin.y));
CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox),
CGContextGetClipBoundingBox(context));
CGContextConcatCTM(context, transform);
CGContextDrawPDFPage(context, pageRef);
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
isWorking=NO;
return finalImage;
}
My understanding is this function is also called in background threads. Here pdf is class variable. am I doing anything wrong?