iphone - Memory usage climbing when popping out of ALAssetslibrary during enumeration -
i have issue see memory usage climbing (but no obvious leaks in instruments) in app.
i have test project 2 viewcontrollers: mainviewcontroller , photoviewcontroller. mainviewcontroller contains single button pushes photoviewcontroller via uinavigationcontroller pushviewcontroller method.
in photoviewcontroller, using alassetslibrary populate uitableview images. in 2 parts. first, check see assetgroups available, need show images camera roll , photolibrary. once done, call method enumerate through actual assets.
here strange behavior: if push photoviewcontroller , let finish entire enumeration , populate uitableview, , pop out mainviewcontroller, fine.
however, if repeatedly , rapidly push , pop out of photoviewcontroller (while hasn't yet finished enumerating , populating uitableiew),then see memory usage gradually climbing until app dies. don't see obvious leaks in instruments.
i don't know relevant code, here 2 methods use enumerate. of course, in dealloc, releasing relevant ivars.
is there way cancel enumeration upon pop?
just note, basing test code off project (https://github.com/elc/elcimagepickercontroller), although heavily customized. however, tested code , same issue happens. note see memory usage climb if have sufficient alassets enumerate. if there few, finish enumerating beforeyou couldpop out.
thank you!
- (void)getassetgroups { // load albums assetgroups dispatch_async(dispatch_get_main_queue(), ^ { nsautoreleasepool *pool = [[nsautoreleasepool alloc] init]; // group enumerator block void (^assetgroupenumerator)(alassetsgroup *, bool *) = ^(alassetsgroup *group, bool *stop) { if (group == nil) { // check data available if([savedphotosgroup numberofassets] > 0 && [librarygroup numberofassets] > 0) { // user has both camera roll , photo library albums self.tabledata = [nsmutabledictionary dictionarywithobjectsandkeys: savedphotoassets, nslocalizedstring(@"photopicker_cameraroll", nil), libraryphotosassets, nslocalizedstring(@"photopicker_photolibrary", nil), nil]; self.sectionkeys = [nsarray arraywithobjects:nslocalizedstring(@"photopicker_cameraroll", nil), nslocalizedstring(@"photopicker_photolibrary", nil), nil]; } else if([librarygroup numberofassets] == 0) { // user has camera roll self.tabledata = [nsmutabledictionary dictionarywithobjectsandkeys: savedphotoassets, nslocalizedstring(@"photopicker_cameraroll", nil), nil]; self.sectionkeys = [nsarray arraywithobjects:nslocalizedstring(@"photopicker_cameraroll", nil), nil]; } else { //user has photo library self.tabledata = [nsmutabledictionary dictionarywithobjectsandkeys: libraryphotosassets, nslocalizedstring(@"photopicker_photolibrary", nil), nil]; self.sectionkeys = [nsarray arraywithobjects:nslocalizedstring(@"photopicker_photolibrary", nil), nil]; } nslog(@"done enumerating groups"); [self performselectorinbackground:@selector(enumeratephotos) withobject:nil]; [self.tview performselector:@selector(reloaddata) withobject:nil afterdelay:1]; return; } alassetsgrouptype grouptype = [[group valueforproperty:alassetsgrouppropertytype] unsignedintvalue]; if(grouptype == alassetsgroupsavedphotos) { self.savedphotosgroup = group; } else if(grouptype == alassetsgrouplibrary) { self.librarygroup = group; } }; // group enumerator failure block void (^assetgroupenumberatorfailure)(nserror *) = ^(nserror *error) { nslog(@"a problem occured %@", [error description]); }; // enumerate albums [library enumerategroupswithtypes: alassetsgroupsavedphotos | alassetsgrouplibrary usingblock:assetgroupenumerator failureblock:assetgroupenumberatorfailure]; nslog(@"draining pool"); [pool drain]; }); }
-(void)enumeratephotos { nsautoreleasepool *pool = [[nsautoreleasepool alloc] init];
nslog(@"enumerating photos"); [savedphotosgroup enumerateassetsusingblock:^(alasset *result, nsuinteger index, bool *stop) { if(result == nil) { return; } customasset *customasset = [[[customasset alloc] initwithasset:result] autorelease]; [customasset setparent:self]; [savedphotoassets addobject:customasset]; }]; [librarygroup enumerateassetsusingblock:^(alasset *result, nsuinteger index, bool *stop) { if(result == nil) { return; } customasset *customasset = [[[customasset alloc] initwithasset:result] autorelease]; [customasset setparent:self]; [libraryphotosassets addobject:customasset]; }]; nslog(@"done enumerating photos"); [tview performselectoronmainthread:@selector(reloaddata) withobject:nil waituntildone:no]; // if want re-select assets if(assetstorestore) { for(nsdictionary *dict in assetstorestore) { nsindexpath *indexpathtorestore = [dict objectforkey:@"selectedassetindexpath"]; int tagtorestore = [[dict objectforkey:@"selectedassettag"] intvalue]; [self selectassetwithindexpath:indexpathtorestore andindex:tagtorestore]; } } [pool drain]; }
correct me if i'm wrong, thought using autorelease pools supposed done now:
@autoreleasepool { (statements) }
that worked me.
Comments
Post a Comment