Merge pull request #15575 from stevetranby/capturescreen-drain-autorelease

Prevent memory leak: force drain on autoreleased `data`.
This commit is contained in:
minggo 2016-05-06 16:57:29 +08:00
commit f34acca188
1 changed files with 12 additions and 14 deletions

View File

@ -99,22 +99,20 @@ bool cocos2d::Image::saveToFile(const std::string& filename, bool isToRGB)
CGImageRelease(iref);
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(provider);
NSData *data;
if (saveToPNG)
{
data = UIImagePNGRepresentation(image);
// NOTE: Prevent memory leak. Requires ARC enabled.
@autoreleasepool {
NSData *data;
if (saveToPNG) {
data = UIImagePNGRepresentation(image);
} else {
data = UIImageJPEGRepresentation(image, 1.0f);
}
[data writeToFile:[NSString stringWithUTF8String:filename.c_str()] atomically:YES];
}
else
{
data = UIImageJPEGRepresentation(image, 1.0f);
}
[data writeToFile:[NSString stringWithUTF8String:filename.c_str()] atomically:YES];
[image release];
if (needToCopyPixels)
{
delete [] pixels;