[выпуск пула]; Сбой моего приложения - PullRequest
0 голосов
/ 16 января 2012

В моем приложении у меня есть цикл, который перемещается на массиве UIImage и делает вещи с этими изображениями. цикл работает в фоновом режиме, поэтому в начале функции я поставил:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

и в конце

[pool release];

В цикле я создаю UIImage, поэтому мне нужно выпустить его, потому что он предупреждает меня, если я не делаю релиз.

Когда приложение завершит цикл и перейдет к

[pool release];

это дает мне BAD_ACCESS ошибку и вылетает приложение.

Редактировать


Это методы в цикле

        UIImage *tmp = [image rotate:UIImageOrientationRight];
        //do some stuff with this image
        [tmp release];

Это метод поворота:

    UIImage*           copy = nil;
    CGRect             bnds = CGRectZero;
    UIImage*           copy = nil;
    CGContextRef       ctxt = nil;
    CGImageRef         imag = self.CGImage;
    CGRect             rect = CGRectZero;
    CGAffineTransform  tran = CGAffineTransformIdentity;

    rect.size.width  = CGImageGetWidth(imag);
    rect.size.height = CGImageGetHeight(imag);

    bnds = rect;

    UIGraphicsBeginImageContext(bnds.size);
    ctxt = UIGraphicsGetCurrentContext();

switch (orient)
{
    case UIImageOrientationLeft:
    case UIImageOrientationLeftMirrored:
    case UIImageOrientationRight:
    case UIImageOrientationRightMirrored:
        CGContextScaleCTM(ctxt, -1.0, 1.0);
        CGContextTranslateCTM(ctxt, -rect.size.height, 0.0);
        break;

    default:
        CGContextScaleCTM(ctxt, 1.0, -1.0);
        CGContextTranslateCTM(ctxt, 0.0, -rect.size.height);
        break;
}

CGContextConcatCTM(ctxt, tran);
CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, imag);

copy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

if (imag) {
    CFRelease(imag);
}

return copy;

Ответы [ 3 ]

4 голосов
/ 16 января 2012

Вы перепроизводите свое изображение после его поворота.

    UIImage *tmp = [image rotate:UIImageOrientationRight];
    //do some stuff with this image
    [tmp release]; // Here

UIGraphicsGetImageFromCurrentImageContext() возвращает автоматически выпущенный объект, поэтому вам не нужно вызывать release для него после его возврата.

Сбой происходит при освобождении NSAutoreleasePool, потому что последний -release не отправляется, пока не будет истощен и отправит правильный вызов освобождения для вашего объекта, который был ранее и ошибочно выпущен вами.

1 голос
/ 16 января 2012

Возможно, вы выпускаете некоторые объекты, которые вы создали, но не владеете ими между моментом создания пула и его повторного выпуска.

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSString *s = [NSString stringWithFormat:@"%d", 2];
// Your string now has a retain count of one, but it's autoreleased. So when the pool
// gets released it'll release the string

[s release];
// You decrease the retain count to zero, so the object gets destroyed
// s now points to a deallocated object

[pool release];
// The pool gets destroyed, so it tries to send a release method to your string. However,
// the string doesn't exist anymore so an error occurs.
0 голосов
/ 16 января 2012

Я думаю, что ваш сбой, вероятно, связан с тем, что пул авто-релиза освобождает UIImages, а не с выпуском пула авто-релиза.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...