Need __block for ios4 for block weak ref in DTAttributedTextContentView.m #165

Merged
merged 1 commit into from Apr 9, 2012

3 participants

@tonycn

Just look up some information about arc library used in non-arc, and found __block is need in ios4 since __weak is not supported in ios4. Sorry to split the issue to two pull request

@odrobnik odrobnik merged commit 30859d4 into Cocoanetics:master Apr 9, 2012
@odrobnik

Don't use use __unsafe_unretained for these kinds of cases? Because __block still is strong, causing the leak on iOS 4 AFAIK

@jonsterling

@Cocoanetics Yes, this is correct. Don't use __block unless you really need to change the value of a variable from within block scope; it was merely a coincidence that it used to be a non-retaining reference. Now, it will cause a retain cycle.

(So, __unsafe_unretained should be used.)

@odrobnik

So I'm waiting for the third pull request that finally gets it right ... ;-)

@tonycn

@Cocoanetics I am a little puzzled by the comments, so "__block __weak" fix the issue, right?

From my understanding, __block makes the local variable mutable and avoid retaining by block, so add "__block __weak" should fix the issue.
By the way, is DTCoreText works for 4.0 since core text is supported from 3.2.

@odrobnik

__block only means that the block does not create a copy of the variable but modifies the original outside.
Any local variable is a strong reference under ARC. Unless you specify __unsafe_unretained or weak.

I believe that __unsafe_unretained is the correct method here, block is not needed because we only want a non-retaining reference and don't need to modify the weakself

@tonycn

@Cocoanetics Got it! __unsafe_unretained is the right way to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment