내 코드에서 이미지의 크기를 지정된 크기로 늘립니다. 코드가 지금까지 잘 작동합니다. "UIGraphicsBeginImageContext()"가 새 이미지의 메모리를 해제하지 않는다는 문제점이 있습니다. 따라서 약 10 분 후에 메모리가 가득 차고 IOS로 앱이 종료됩니다.UIGraphicsBeginImageContext는 메모리 누출을 초래합니다.
누구에게이 문제의 해결책이 있습니까? 이 코드에 의해 호출
- (CCSprite *)createStretchedSignFromString:(NSString *)string withMaxSize:(CGSize)maxSize withImage:(UIImage *)signImage
{
// Create a new image that will be stretched with 10 px cap on each side
UIImage *stretchableSignImage = [signImage stretchableImageWithLeftCapWidth:10 topCapHeight:10];
// Set size for new image
CGSize newImageSize = CGSizeMake(260.f, 78.0f);
// Create new graphics context with size of the answer string and some cap
UIGraphicsBeginImageContext(newImageSize);
// Stretch image to the size of the answer string
[stretchableSignImage drawInRect:CGRectMake(0.0f, 0.0f, newImageSize.width, newImageSize.height)];
// Create new image from the context
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
// End graphics context
UIGraphicsEndImageContext();
// Create new texture from the stretched
CCTexture2D *tex = [[CCTexture2D alloc] initWithImage:resizedImage];
CCSprite *spriteWithTex = [CCSprite spriteWithTexture:tex];
[[CCTextureCache sharedTextureCache] removeTexture:tex];
[tex release];
// Return new sprite for the sign with the texture
return spriteWithTex;
}
:
// Create image from image path
UIImage *targetSignImage = [UIImage imageWithContentsOfFile:targetSignFileName];
// Create new sprite for the sign with the texture
CCSprite *plainSign = [self createStretchedSignFromString:answerString withMaxSize:CGSizeMake(260.0f, 78.0f) withImage:targetSignImage];
지금까지 주셔서 감사합니다.
NSThread로 만들고 NSAutoreleasePool을 사용하십시오. 제 제안입니다. – SAKrisT
나는 createStretchedSignFromString을 유지한다고 생각하고 해제해야합니다. * plainSign * – SAKrisT
'targetSignImage'와'plainSign'은 자동으로 릴리즈되므로, 나는 그것들을 해제 할 필요가 없습니다. 나는 이미 그것을 시도했다. –