Skip to content

Commit

Permalink
Add countermeasure to avoid crash in cxx_destruct during deallocati…
Browse files Browse the repository at this point in the history
…on of mapping result
  • Loading branch information
blakewatters committed Feb 25, 2013
1 parent f36dcde commit 490b233
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Code/Network/RKManagedObjectRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ - (id)initWithHTTPRequestOperation:(RKHTTPRequestOperation *)requestOperation re
return self;
}

/**
NOTE: This dealloc implementation attempts to avoid crashes coming from Core Data due to the ordering of deallocations under ARC. If the MOC is deallocated before its managed objects, it can trigger a crash. We dispose of the mapping result and reset the private context to avoid this situation. The crash manifests itself in `cxx_destruct`
[sbw - 2/25/2013]
*/
- (void)dealloc
{
_mappingResult = nil;
_responseMapperOperation = nil;
_privateContext = nil;
}

- (void)setTargetObject:(id)targetObject
{
[super setTargetObject:targetObject];
Expand Down
5 changes: 4 additions & 1 deletion Code/Network/RKObjectRequestOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
@see `RKMIMETypeSerialization`
@see `RKManagedObjectRequestOperation`
*/
@interface RKObjectRequestOperation : NSOperation <RKMapperOperationDelegate>
@interface RKObjectRequestOperation : NSOperation <RKMapperOperationDelegate> {
@protected
RKMappingResult *_mappingResult;
}

///-----------------------------------------------
/// @name Initializing an Object Request Operation
Expand Down

0 comments on commit 490b233

Please sign in to comment.