jspahrsummers / libextobjc

A Cocoa library to extend the Objective-C programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Do I have to use weakify/strongfy for a instance variable declared as weak?

Ricardo1980 opened this issue · comments

Hello!
If I use something like:

@Property (nonatomic,weak) RKObjectRequestOperation *hotspotsOperation;

and I write this inside a block:

self.hotspotsOperation=nil;

I don't see any compiler warning. Does it mean there is no cycle?

The absence of compiler warnings does not mean there's an absence of retain cycles. Clang can't statically detect all possible cycles.

Note that it's not the property being captured in the block, in that sample. You're capturing self, and calling a method upon it.

So, if I use self.request=nil I am capturing self (it doesn't import if the property is weak or strong), but what about the case of using _request (that is, not using the accessors) remembering that is weak?
Thanks.

Instance variables also capture self, not the variable itself. I would recommend consulting Apple's documentation about ARC, blocks, and memory management—they explain all of this in detail.