0

I encountered a problem when using СП

for (int16_t j = 0; j <= 1/kAlphaStep; j++) {
            UIImage *blendingImage = [UIImage imageByBlendingImage:firstImage andImage:secondImage alpha:kAlphaStep*j];
            buffer = [self pixelBufferFromImage:blendingImage andSize:size];
...}

And

- (CVPixelBufferRef)pixelBufferFromImage:(UIImage *)img andSize:(CGSize)size {
CGImageRef image = img.CGImage;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
                         [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
                         nil];
CVPixelBufferRef pxbuffer = NULL;

CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, size.width,
                                      size.height, kCVPixelFormatType_32ARGB, (__bridge CFDictionaryRef) options,
                                      &pxbuffer);
NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);
...
return pxbuffer;

}

And while I'm in the loop, all CGImageRef in memory.

If I use

if (image) {
    CGImageRelease(image);
}

app crashed. Please help me!!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
  • Your's image is owned by pxbuffer. You need release pxbuffer instead. – Cy-4AH Sep 02 '14 at 12:38
  • 2
    You should rename your's `pixelBufferFromImage` to `createPixelBufferFromImage` to avoid misunderstanding. – Cy-4AH Sep 02 '14 at 12:42
  • @Cy-4AH `pxbuffer` is releasing in first loop `if(buffer) { CVBufferRelease(buffer); [NSThread sleepForTimeInterval:0.05]; }` Problem exactly in CGImageRef. If i'm releasing **image** in loop - it's not memory warning, but crashed after `viewDidApear`. If i'm not releasing **image** it's not crashed, but have many memory warnings – Khalbaevdm Sep 03 '14 at 06:23
  • You cannot do all that image processing in a loop. Instead, do the process one at a time in a timer callback. That way, only 1 processing steps is done every N ms. The way you wrote the code will just crash your device, so you need to start over with a step by step approach spread out over time. – MoDJ Nov 29 '14 at 04:13

0 Answers0