Reputation: 77646
1- Is these anything wrong with the way i am deallocing the object?
2- Does my dealloc override the dealloc for NSManagedObject?
3- Do i need to dealloc super even though my object is an NSManagedObject type and core data ia responsible for it?
@interface MyClass : NSManagedObject
@property (nonatomic, retain) NSString *coreDataString;
@property (nonatomic, retain) NSNumber *coreDataNumber;
@property (nonatomic, retain) CoolObject *coolObject;
@end
.
@implementation MyClass
@dynamic coreDataString;
@dynamic coreDataNumber;
@synthesize coolObject;
- (void)dealloc
{
[self.coolObject release];
}
@end
Upvotes: 1
Views: 675
Reputation: 71
You should always call [super dealloc] in the dealloc method. But in subclasses of NSManagedObject you should never use the dealloc method at all. use - (void)didTurnIntoFault instead.
Upvotes: 2
Reputation: 94773
You should call release on the member variable directly instead of using the property. You also should still call the super dealloc. So your dealloc would look like this:
- (void)dealloc
{
[coolObject release];
coolObject = nil;
[super dealloc];
}
Otherwise, you can set the property to nil which will automatically release the local variable if necessary. The above way is preferred so you don't accidentally run a complicated function that could be overriding the property's setter.
Upvotes: 2
Reputation: 14414
You are overriding the parents - (void)dealloc
method. When you override a parent object's method, the parent's method is never called until you explicitly call the super's method. In your case, the parent's - (void)dealloc
is not called. To fix this, you must call [super dealloc]
to ensure that the parent's instance variables are deallocated too.
Upvotes: 0
Reputation: 94834
[super dealloc]
.[super dealloc]
at the end of your dealloc method. Otherwise memory will not be freed correctly.Upvotes: 4