Monday 15 June 2015

ios - Instruments Indicates Memory Leak on Instantiation of NSMutableDictionary -



ios - Instruments Indicates Memory Leak on Instantiation of NSMutableDictionary -

locating memory leaks not strong suit, appears me instruments indicating memory leak upon creation of, , setting of values for, nsmutabledictionary. (i using arc). makes no sense me of yet, might know happening.

i have delegate method called on completion of taking photo device's camera: (i have added comment lines raising issue).

- (void)finishimagecaptureforbuffer:(cmsamplebufferref)imagedatasamplebuffer witherror:(nserror *)error shouldsave:(bool)save { //do stuff... if (save) { cfdictionaryref attachments = cmcopydictionaryofattachments(kcfallocatordefault, self.imagedatasamplebuffer, kcmattachmentmode_shouldpropagate); cfmutabledictionaryref mutableattachments = cfdictionarycreatemutablecopy(null, 0, attachments); //memory leak!!!!!// nsmutabledictionary *gps = [nsmutabledictionary dictionary]; cllocation *location = [manager location]; [gps setobject:@"" forkey:(nsstring *)kcgimagepropertygpsversion]; nsdateformatter *formatter = [[nsdateformatter alloc] init]; [formatter setdateformat:@"hh:mm:ss.ssssss"]; [formatter settimezone:[nstimezone timezonewithabbreviation:@"utc"]]; //memory leak!!!!!// [gps setobject:objectornull([formatter stringfromdate:location.timestamp]) forkey:(nsstring *)kcgimagepropertygpstimestamp]; [gps setobject:(location.coordinate.latitude < 0) ? @"s" : @"n" forkey:(nsstring *)kcgimagepropertygpslatituderef]; //memory leak!!!!! [gps setobject:objectornull([nsnumber numberwithdouble:fabs(location.coordinate.latitude)]) forkey:(nsstring *)kcgimagepropertygpslatitude]; [gps setobject: (location.coordinate.longitude < 0) ? @"w" : @"e" forkey:(nsstring *)kcgimagepropertygpslongituderef]; //memory leak!!! [gps setobject:objectornull([nsnumber numberwithdouble:fabs(location.coordinate.longitude)]) forkey:(nsstring *)kcgimagepropertygpslongitude]; cfdictionarysetvalue(mutableattachments, kcgimagepropertygpsdictionary, cfbridgingretain(gps)); nsdata *imagedata = [avcapturestillimageoutput jpegstillimagensdatarepresentation:self.imagedatasamplebuffer]; alassetslibrary *library = [[alassetslibrary alloc] init]; [library writeimagedatatosavedphotosalbum:imagedata metadata:(__bridge id)mutableattachments completionblock:completionblock]; if ([[self delegate] respondstoselector:@selector(capturemanagerstillimagecaptured:)]) { [[self delegate] capturemanagerstillimagecaptured:self]; } cfrelease(attachments); cfrelease(mutableattachments); cfrelease(self.imagedatasamplebuffer); } else { ...

where objectornull checks see if value inserting exists, , if not, [nsnull null] added dictionary.

as aside, issue appears when running ios7 not ios8.

try replacing

cfdictionarysetvalue(mutableattachments, kcgimagepropertygpsdictionary, cfbridgingretain(gps));

with

cfdictionarysetvalue(mutableattachments, kcgimagepropertygpsdictionary, (__bridge cfdictionaryref)gps);

ios memory-management memory-leaks instruments nsmutabledictionary

No comments:

Post a Comment