major memory problem/crash with UIImage
Hi,
Our app needs to render the screen to an UIImage and everytime we do that, the memory utilization of app goes up by about 0.3M [as shown by XCode execution panel, but the Instruments panel shows 3M - see below] eventually causing memory warning and crashing.
The code used is simple - from the example code of Apple:
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I've tried many ways to reclaim this memory, but there is unbounded growth.
We've checked it many times and there are no leaks, etc.
It is not allocated using imageNamed so I understand it is not cached - regardless we even called [super didReceiveMemoryWarning] to try to flush the cache, but no luck.
In XCode instruments, the allocations show huge nearly 3MB growth as below:
# | Event Type | ∆ RefCt | RefCt | Timestamp | Responsible Library | Responsible Caller |
0 | VM Alloc | 02:08.145.871 | CoreGraphics | CGDataProviderCreateWithCopyOfData |
The LiveBytes increases by 3MB everytime the UIImage is allocated and RELEASED by the app.
Graph | Category | Live Bytes | # Living | # Transient | Overall Bytes | # Overall | Bytes Allocated (Net / Overall) |
1 | All Heap & Anonymous VM | 12.16 MB | 11263 | 3422178 | 597.30 MB | 3433441 | <XRRatioObject: 0x7fbca501d950> %0.02, %0.98 |
WHY is this NOT RELEASED by iOS? Can someone help - our app is crashing and rendering the screen to an image is a core part of the functionality.
Thanks,
RFS
iPhone 5, iOS 7.0.1