Search code examples
iosobjective-cmemory-managementnsblockoperation

When does the NSBlock get freed?


In a view controller I have a property of NSBlock of copy type as follow

@interface myViewController
@property(nonatomic, copy) MyBlock *block;
@end

@implementation myViewController

@end

When my application pop from myViewController then my block will be release automatically?

Note: My project is ARC enabled.


Solution

  • The block is deallocated when the view controller is deallocated. Whether the view controller is deallocated on pop or not depends on your app.

    Anyway, dealloc on the view controller -> destruction of the block. Unless you've shared the block pointer with other objects in your view controller code, of course.