0

I got bad access error when trying to get the reference image back from UIImage:

CGImageRef imageRef = mat2CGImageRef(mat);
_documentUIImage = [[UIImage alloc] initWithCGImage:imageRef];
CGImageRelease(imageRef);

After that if I want to get the CGImageRef from the uiimage I got bad access error!

return _documentUIImage.CGImage

I believe that the variable UIImage should have different address than the image ref.. so why after releasing it I got bad access?

Best regards

Mohanad Kaleia
  • 793
  • 1
  • 9
  • 22

1 Answers1

0

I think the UIImage initWithCGImage simply wraps the CGImage and does not duplicate the data.

In any case the method should retain the CGImage so the CGImageRelease should not be responsible for the exception.

This should lead to conclusion that the CGImageRelease must be removed in your case as the mat2CGImageRef does not retain it. What does this function do anyway? Try to follow the rule that only functions and methods that contain words such as "create", "copy", "alloc" produce the result which needs to be released.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • Thanks for you reply After scanning the code .. the CGImageRef was released in another place as well .. so I kept just one release and it works fine now best regards – Mohanad Kaleia Apr 22 '15 at 13:01