开发者

Objective C , iOS - Received memory warning

开发者 https://www.devze.com 2023-04-12 11:30 出处:网络
i am currently working on an iOS project which makes good progress, but the whole memory thing on iOS is not working properly.

i am currently working on an iOS project which makes good progress, but the whole memory thing on iOS is not working properly.

The iphone camera records a a stream. I have a capture method which is executed via a queue. The camer image is converted to greyscale. It works well but after a while gives some memory warning and closes the app, because its out of memory.

I have spotted the error source to here

CGColorSpaceRef colorSpaceGray = CGColorSpaceCreateDeviceGray();
CGContextRef newContextGray = CGBitmapContextCreate(baseAddressGray, width, height, 8, width, colorSpaceGray, kCGImageAlphaNone);

CGImageRef GrayImage = CGBitmapContextCreateImage(newContextGray);


UIImage *img= [UIImage imageWithCGImage:GrayImage scale:1.0 orientation:UIImageOrientationRight];
[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:img waitUntilDone:NO];



free(baseAddressGray);
CGColorSpaceRelease(colorSpaceGray);
CGContextRelease(newContextGray);


CVPixelBufferUnlockBaseAddress(imageBuffer,0);

All lies inside an autorelease pool which is drained afterwards. The line which is th source for the crash is

CGContextRef newContextGray = CGBitmapContextCreate(baseAddressGray, width, height, 8,开发者_如何转开发 width, colorSpaceGray, kCGImageAlphaNone);

From my understanding there should be no memory problem here, because

CGColorSpaceRelease(colorSpaceGray);
CGContextRelease(newContextGray);

are released.

What am i doing wrong here, or what is missing?


You are not releasing GrayImage in line 4 of your code sample.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号