Here's a little example of using weak arguments:
@interface MYTestObject : NSObject
@end
@implementation MYTestObject {
void(^_block)(void);
}
- (void)dealloc {
NSLog(@"DEALLOC!");
}
- (id)init {
if (self = [super init]) {
[self doSomethingWithObject:self];
}
return self;
}
- (void)doSomethingWithObject:(id __weak /* <- weak argument! */)obj {
_block = ^{
NSLog(@"%p", obj);
};
}
@end
And it works: -dealloc
is called!
Also, if you remove __weak
you'll get a retain-cycle and it's absolutely correct.
Wonder, if that's just a side-effect and it's completely unsafe to use weak arguments? Or is it a specified behavior and I'm just a bad google-user?