问题
I have two NSManagedObject:
- DataEntered
- Provence
There is a relation between them: DataEntered must have ONE Provence, and Provence may have one/multiple DataEntered.
All is working well, but when using Instruments and Allocations, every time I set the Provence to DataEntered, a new _CDSnapshot_Provence_ appears in #Living:
Provence * provence = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[self.dataEntered setAddress_provence:provence];
The setter for Provence in DataEntered is managed by CoreData, there is no customization.
When I save DataEntered, is saved correctly. What can cause the creation of multiple living _CDSnapshot_Provence_ ?
Thanks!
@class Provence;
@interface DataEntered : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, strong) Provence *address_provence;
@end
@class Provence;
@interface DataEntered : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, strong) Provence *address_provence;
@end
@class DataEntered;
@interface Provence : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSSet *dataEnteredAddress_Provence;
@end
@interface Provence (CoreDataGeneratedAccessors)
- (void)addDataEnteredAddress_ProvenceObject:(DataEntered *)value;
- (void)removeDataEnteredAddress_ProvenceObject:(DataEntered *)value;
- (void)addDataEnteredAddress_Provence:(NSSet *)values;
- (void)removeDataEnteredAddress_Provence:(NSSet *)values;
@end
#import "Provence.h"
#import "DataEntered.h"
@implementation Provence
@dynamic name;
@dynamic dataEnteredAddress_Provence;
@end
回答1:
I saw exactly the same thing and I believe that this is to be expected.
See the section Conflict Detection and Optimistic Locking in the Apple docs at https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdChangeManagement.html
"When Core Data fetches an object from a persistent store, it takes a snapshot of its state. A snapshot is a dictionary of an object’s persistent properties—typically all its attributes and the global IDs of any objects to which it has a to-one relationship."
There is also a section at that same link that is useful to read - Snapshot Management
The problem I ran into was getting Core Data to release its memory allocations after I had faulted all the managed objects or did a context reset.
I just published a blog posting on this and related topics: Core Data issues with memory allocation - http://finalize.com/2013/01/04/core-data-issues-with-memory-allocation/
Hope this helps.
Scott
来源:https://stackoverflow.com/questions/12979085/setter-for-nsmanagedobject-creates-cdsnapshot-provence