I have a singleton and I want to capture it inside a block. I know that variables are retained inside a block because a constant copy of the objects passed is created and never deallocated unless using a weak instance of that object. The curiosity I have is whether the same behaviour is applied to a statically allocated variable. Here is my code (self is the sharedInstance of Class):
+ (Class *)sharedInstance
{
static Class *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[Class alloc] init];
});
return sharedInstance;
}
[self setBlock:^(NSArray *array)
{
self.property = [array firstObject];
}];
Aucun commentaire:
Enregistrer un commentaire