xcode - CoreData - managedObjectContext:save: is keeping items in the registeredObjects set -


i think missing crucial part of knowledge when comes coredata , wondering if me out. trying create new object entities memory never released after save. have object called userentity contains 2 strings, susername , spassword set uitextfields (see below)

+ (bool)createuserentitywithusername:(nsstring *)susername andpassword:(nsstring *)spassword {     nsarray *user = [self fetchentityswithentityname:@"userentity" withpredicate:[nspredicate predicatewithformat:@"(susername = %@)", susername]];      if ([user count] == 0)     {         // nslog (@"user created");          userentity * newentry = [nsentitydescription insertnewobjectforentityforname:@"userentity"                                                               inmanagedobjectcontext:[singleton sharedsingleton].managedobjectcontext];         //  setup params         newentry.susername = susername;         newentry.spassword = spassword;          [[singleton sharedsingleton] savecontext];         user = nil;          return yes;     }      user = nil;      // nslog (@"user found");     return no; } 

this called view controller follows:

if ([singleton createuserentitywithusername:self.tfusername.text andpassword:self.tfpassword.text])     { } 

and savecontext looks this:

   - (void)savecontext     {         nserror *error = nil;         nsmanagedobjectcontext *managedobjectcontext = [self managedobjectcontext];         if (managedobjectcontext != nil) {                     if ([managedobjectcontext haschanges] && ![managedobjectcontext save:&error]) {                nslog(@"unresolved error %@, %@", error, [error userinfo]);             }             else             {                 nslog(@"save successful");             }         }         managedobjectcontext = nil;     } 

this saves fine, however, if break after singleton create... function can see following:

po [[singleton sharedsingleton].managedobjectcontext registeredobjects] {(     <userentity: 0xa3a4dd0> (entity: userentity; id: 0xa3b41d0 <x-coredata://8f241f56-d1a2-4bc2-a575-ff9972b15629/userentity/p1> ; data: {     spassword = ejd;     susername = ejd2; }) )} 

i under impression nsmanagedobjectcontext cleared set after objects changes have been saved? nsmanagedobjectcontext etc, can explain what's going on can't figure out if i'm meant explicitly releasing items in list, or memory management going wrong.

any appreciated.

do -reset on moc. , make sure references nsmo's live in moc invalidated, too.

btw, don't store passwords in core data. they're saved unencrypted, , can read them. use keychain instead.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -