I have used some code from Apple’s ‘Camera Programming Topics for iOS’ guide as follows:
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to only take picture:
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
// Hides the controls for moving & scaling pictures, or for trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
[cameraUI release];
However, when I ‘Analyze’ my code, Xcode says I have a potential leak from the following line:
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
I have no other release commands than those shown above. Given the array in question is an attribute of cameraUI (which is released), Im not sure what I should do (if anything).
Any thoughts?
Unless
cameraUI.mediaTypesproperty is defined withassign, there is indeed a leak here. It may help to break up the line into multiple steps, just for instruction.If
cameraUItakes care of its own memory, it shouldn’t matter what you assign or when. But, in that first line, you’re constructing a variable but never releasing it. So, how do you fix this? The standard way to fix it is by autoreleasing during construction.If you’re working with very large objects that must be released as soon as possible, you’ll need to manually release it once it’s been passed to
cameraUI:Only use the second form if you need it – it’s much more prone to error.