iphone - "[CFString release]: message sent to deallocated instance" when using CoreData -
i have started using coredata in project. without pieces of code codedata project working pretty fine. added methods accessing nsmanagedobjectcontext coredata project template. try create new coredata object following code:
- (void)savesearchresulttohistory:(nsarray *) productsarray { [productsarray retain]; nslog(@"context: %@", self.managedobjectcontext); product *product = [nsentitydescription insertnewobjectforentityforname:@"product" inmanagedobjectcontext:self.managedobjectcontext]; product.productid = [(product *) [productsarray objectatindex:0] productid]; nserror *error; if (![self.managedobjectcontext save:&error]) { nslog(@"whoops, couldn't save: %@", [error localizeddescription]); } [productsarray release]; }
when method ran once fine, when try run second time, processing stopped at:
product *product = [nsentitydescription insertnewobjectforentityforname:@"product" inmanagedobjectcontext:self.managedobjectcontext];
with following error message in console:
[cfstring retain]: message sent deallocated instance 0x5a23b0
any ideas might wrong? thanks!
first off not need save context every time add something, save when app closes or goes in background.
the error getting looks on release nsstring where.
to check if error isn't in coredata context use save function:
- (void)savecontext { if ([self.managedobjectcontext haschanges]) { nserror *error = nil; if (![self.managedobjectcontext save:&error]) { dbgprint(@"failed save data store: %@", [error localizeddescription]); nsarray* detailederrors = [[error userinfo] objectforkey:nsdetailederrorskey]; if (detailederrors != nil && [detailederrors count] > 0) { for(nserror* detailederror in detailederrors) { dbgprint(@"--detailederror: %@", [detailederror userinfo]); } } else { dbgprint(@" %@", [error userinfo]); } } } }
Comments
Post a Comment