Basic data. How to check if properties of managed objects are freed

I created a program that uses basic data, and it works great.

Since then, I tried to transfer all my calls to the main data methods and execute the routines in a class that is autonomous. My main program then creates this class and makes some calls to the base method to this class, and then the class executes all the main data behind the scenes. I am faced with the fact that sometimes I find that when I get the managed object from the context, I will have a valid object, but its properties have been freed and I will cause a crash. I played with zombies and looked for memory leaks, and what I put together seems like the execution loop is probably responsible for freeing the memory, but I'm not sure.

Is there a way to determine if this memory has been freed and force the kernel data to return it if I need to access it? My managedObjectContext is never freed, and the fetchedResultsController never does this.

I thought maybe I need to use the [managedObjectContext refreshObject: mergeData:] method or the [managedObjectContext setRetainsRegisteredObjects:] method. Although, I got the impression that the latter may not be the best choice, since it will be more intense in memory (from what I understand).

These errors appeared only when I moved the main data calls to another class file and they are random when they appear.

Any insight would be appreciated.

-Ryan

+3
4

, , . - :

NSArray *array = [moc executeFetchRequest:request error:&error];

, , , , ​​ . , .

. , .

+1

, , Core Data. ( ). "", , ivars? , release d didTurnIntoFault alloc d (, ).

+1

. . , .

Apple http://developer.apple.com/library/IOs/#documentation/Cocoa/Conceptual/CoreData/Articles/cdMemory.html " " , .

[myMangedObjectContext setRetainsRegisteredObjects:YES];

( init (initWithNibName ) .)

, , . .

, .

+1

, CoreData . , . ( , , .)

:


1) "fetchFiredObject" CoreData. , , , , " ", , :

aManagedObject *myManagedObject = [myCoreDataHandler.managedObjectStorageArray objectAtIndex:1];
int x = myManagedObject.someVariable.intValue;

:

aManagedObject *myManagedObject = [myCoreDataHandler fetchFiredObjectAtIndex:1];
int x = myManagedObject.someVariable.intValue;

myCoreDataHandler fetchFiredObjectAtIndex: , i, fetchRequest , ..: D


2) viewController, "myCoreDataHandler" . , viewController. childviewDidLoad, myCoreDataHandler, , viewDidLoad , . , " " viewDidLoad , viewDidLoad! viewController.

0
source

Source: https://habr.com/ru/post/1740854/


All Articles