mirror of https://github.com/axmolengine/axmol.git
Merge pull request #15575 from stevetranby/capturescreen-drain-autorelease
Prevent memory leak: force drain on autoreleased `data`.
This commit is contained in:
commit
f34acca188
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue