Search code examples
objective-cmemory-managementdelegatesdealloc

Should we release a delegate in the dealloc method?


hello I have a small question in objective-C memory management.

I know that if a property is retained we should release it in the dealloc method. ex:

@property (nonatomic, retain) NSString *title;

in the dealloc method:

-(void) dealloc
{ 
    [title release];
    [super dealloc];
}

But if we declare a delegate (using assign)

@property (nonatomic, assign) id titleDelegate

Should we release it in the dealloc method?

[titleDelegate release]

Thanks in advance for any tips.


Solution

  • No. You have not allocated memory or retained .So don't release it. make it nil. You will release memory for an object only if you are the owner of it.