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?


P.S.

Here's my question on SO:
http://stackoverflow.com/questions/18316803/objective-c-arc-is-it-correct-to-use-weak-arguments
_______________________________________________
cfe-users mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to