[cfe-users] Is it correct to use __weak arguments in Obj-C?

Andrew Pleshkov andrew.pleshkov at gmail.com
Tue Aug 20 01:01:23 PDT 2013

Here's a little example of using weak arguments:

@interface MYTestObject : NSObject
@implementation MYTestObject {
- (void)dealloc {
- (id)init {
   if (self = [super init]) {
      [self doSomethingWithObject:self];
   return self;}
- (void)doSomethingWithObject:(id __weak /* <- weak argument! */)obj {
   _block = ^{
      NSLog(@"%p", obj);

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?


Here's my question on SO:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20130820/e7a34ab7/attachment.html>

More information about the cfe-users mailing list