2012-07-11 5 views
0

난 내 응용 프로그램이 버그를 얻을 왜 내가 두 번째[있는 UIImage 크기] : 할당이 해제 된 인스턴스에 보낸 메시지 0x8452560

-(UIImage *)rotateImage:(UIImage *)image{ 
    // calculate the size of the rotated view's containing box for our drawing space 
    CGSize rotatedSize = image.size; 

    // Create the bitmap context 
    UIGraphicsBeginImageContext(rotatedSize); 
    CGContextRef bitmap = UIGraphicsGetCurrentContext(); 

    // Move the origin to the middle of the image so we will rotate and scale around the center. 
    CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2); 

    // // Rotate the image context 
    CGContextRotateCTM(bitmap, DegreesToRadians(90)); 

    // Now, draw the rotated/scaled image into the context 
    CGContextScaleCTM(bitmap, 1.0, -1.0); 
    CGContextDrawImage(bitmap, CGRectMake(-image.size.width/2, -image.size.height/2, image.size.width, image.size.height), image.CGImage); 

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return newImage; 

} 

에서 이미지를 회전 할 때 알려진 해달라고 난에 의해이 함수를 호출 :

NSLog(@"%f %f",rotatedOriginImage.size.width,rotatedOriginImage.size.height); 
    rotatedOriginImage = [self rotateImage:rotatedOriginImage]; 

2012-07-11 17:22:50.825 meshtiles[3330:707] 600.000000 600.000000 

을하지만 제 시점 :

처음에 그 기록

01,235 당신은 ARC를 사용하지 않는 경우 16,
2012-07-11 17:22:55.253 meshtiles[3330:707] *** -[UIImage size]: message sent to deallocated instance 0x8452560 

이 경우에 대한 지원, 당신은 당신의 방법에서 오토 릴리즈 객체 newImage를 반환하는 나에게

+0

'rotateOriginImage'가 어디서 왔는지 보여줄 필요가있다. 문제는'-rotateImage :'메소드에 있지 않다. 문제는 당신이 제공 한 객체가 과량 릴리즈되었다는 것이다. – joerick

+0

첫회와 두 번째로 무엇을 의미합니까? 회전 전과 회전 후입니까? rotateOriginImage를 확인해야합니다. 코드에서 어딘가에 릴리스 되었습니까? – AJS

+0

"rotateImage"메서드가 호출 된 후 "rotateOriginImage"가 설정되고 이미지가 반환됩니다. 그리고 설정하기 전에 크기에 액세스하고 있습니다. NSLog 문은 "rotateImage"메서드가 호출 된 곳의 라인에 있어야합니다. – AJS

답변

2

도와주세요. 다시 가져올 때 보관해야합니다.

rotatedOriginImage = [[self rotateImage:rotatedOriginImage] retain];

그러나 당신은 당신이 rotateImage 전화 후뿐만 아니라 그것을 해제하는 것을 기억해야합니다. 그래서 코드를 바꿔야한다.

+0

많은 도움을 주신 데 대해 감사드립니다. 끝까지 보관하십시오. 정말 마술입니다. 감사합니다. – Makio

+0

@Makio 릴리스에 추가하지 않은 경우 메모리를 과도하게 보유하고 누출 될 수 있습니다. –

관련 문제