Uiimagejpegrepresentation Received Memory Warning

Getting memory warning while using UIImagePickerControllerOriginalImage to get image from UIImagePickerController

I have tried to solve these problem with many ways but didn't get success.
Finally I have changed my approach and used AVCaptureSession to take picture from iPhone camera
Here is the sample code provided by Apple

https://developer.apple.com/library/ios/samplecode/SquareCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011190

All is fine now no memory leaks, performance improved, capturing processes is fast.

UIImageJPEGRepresentation - memory release issue

At the very least, there's no point in allocating and releasing the image on every trip through the loop. It shouldn't leak memory, but it's unnecessary, so move the alloc/init and release out of the loop.

Also, the data returned by UIImageJPEGRepresentation is auto-released, so it'll hang around until the current release pool drains (when you get back to the main event loop). Consider adding:

NSAutoreleasePool* p = [[NSAutoreleasePool alloc] init];

at the top of the loop, and

[p drain] 

at the end. That way you'll not be leaking all of the intermediate memory.

And finally, doing a linear search for the optimal compression setting is probably pretty inefficient. Do a binary search instead.

Received memory warning in UICollectionView iOS 7

its due to assest library. Once u fetched the image using assest libary just store it in some variable and re-use that image in

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

while scrolling the collection view it will fetch the image again and again using asset libary this will cause huge memory leak.

Edit:

 UIImage *img =[imageDictionary objectForKey:imageName];
if(!img)
{

NSURL *asseturl = [NSURL URLWithString:imageName];
img = [McAssetReader readImage:asseturl];
[imageDictionary setObject:img forKey:imageName];
}

where imageDictionary is the Global Dictionay for holding the image.
imageName is the url for particular image.



Related Topics



Leave a reply



Submit