objective c - Reset Core Data driven treeController content -


i run program creates core data content displayed in nsoutlineview using nstreecontroller. second time run program want clean content of nstreecontroller , run method pasted below. method either hangs long time (600 seconds) before finishes or crashes. if have few entities (500-1000) in nstreecontroller takes less time compared if have lot (200,000) entities pass method, if passes @ all. need know if there better way clear/refresh/reset content of nstreecontroller clear nsoutlineview before re-run program , fill nstreecontroller again. specifically, nsoutlineview respond changes contents of nstreecontroller, , need content of core data driven nstreecontroller able reset.

-(void) cleansdrdfileobjects {     __weak __typeof__(self) weakself = self;     dispatch_async(dispatch_get_main_queue(), ^{              [weakself.outlineview collapseitem:nil collapsechildren:yes];         [weakself.coredatacontroller._coredatahelper.context  performblockandwait:^{              nsentitydescription *entitydescription = [nsentitydescription                                                   entityforname:@"sdrdfileobject"                                        inmanagedobjectcontext:weakself.coredatacontroller._coredatahelper.context];              nsfetchrequest *request = [[nsfetchrequest alloc] init];             [request setentity:entitydescription];              nsarray * result = [weakself.coredatacontroller._coredatahelper.context  executefetchrequest:request error:nil];             (id fileobject in result){                 [weakself.coredatacontroller._coredatahelper.context deleteobject:fileobject];             }             [weakself.coredatacontroller._coredatahelper.context processpendingchanges];              nslog(@"finished deleting objects");         }];     });  } 

the managedobjectcontext (context) run type nsmainqueueconcurrencytype , method run on main thread. suggestions improvements, or useful examples combination of reset/refreshing nsoutlineview + core data appreciated. thanks. cheers, trond

in response @tomharringtons question took picture of time profiler. dont understand why hangs on method, however, after commenting methods out (```processpendingchanges```), still hangs , takes forever finish (6 minutes). seems process gets stuck on main thread , cant continue.

enter image description here

when rerun application, processpendingchanges commented out still hanging.

enter image description here

update

i believe solved uncertain why worked. seems first method went indefinite loop did not release objects. following simple solution worked:

     __weak __typeof__(self) weakself = self;      dispatch_sync(dispatch_get_main_queue(), ^{          [weakself.coredatacontroller._coredatahelper.context reset];       });  

i empty managed object context have delete each entity individually. reset function seems pretty brute force , clean memory , make sure okay? if wants shed light on appreciated.

looking @ again, fetched objects of type in performblockandwait -- blocks main thread because have mainqueueconcurrency , used andwait version of performblock.

you delete each object one-by-one. these objects in tree data structure outlineview attached (see kvo messages in stack trace). these objects have to-many relationships need maintained core data, hell, have cascading delete rule. (see propagatedelete , maintaininverserelationship in stack trace) in event, start requesting both data source , view start doing lot of work, on main thread. try using child moc privatequeueconcurrency if wanted iterate objects in background.

but, comments indicated:

nsmanagedobjectcontext's reset frees memory, , it's fine want here: blow away.

it begs question why load model store on disk in first place, though.

if want core data, not persistence between times run program, can initialize persistentstorecoordinator store of nsinmemorystoretype rather pointing file url.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -