1

假设 UIKit 调用在 iOS 4 中是线程安全的,但是当我尝试在后台线程中渲染 PDF 页面并从视图中拉出图像时,我得到了大量的泄漏。一旦我把它放在前台,它的泄漏就为零。

代码很标准

UIGraphicsBeginImageContext(rect.size);
CGContext ctx = UIGraphicsGetCurrentContext();

// Flip the coordinate system
CGContextTranslateCTM(ctx, 0.0, rect.size.height);
CGContextScaleCTM(ctx, 1.f, -1.f);

// Transform coordinate system to match PDF
NSInteger rotationAngle = CGPDFPageGetRotationAngle(_page);
CGAffineTransform transform = CGPDFPageGetDrawingTransform(_page, kCGPDFCropBox, rect, -rotationAngle, NO);
CGContextConcatCTM(ctx, transform);

CGContextDrawPDFPage(ctx, _page);
UIImage *i = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

如前所述,主线程泄漏 0 次,后台线程泄漏大量。知道为什么吗?

4

1 回答 1

0

代码没有任何问题,也不会导致泄漏。

问题是我在触发此代码时触发了一个保留周期。奇怪的是,当这些调用发生在主线程上时,我没有看到泄漏,但我确实在后台线程上看到了它们。

于 2013-05-24T15:53:36.563 回答