• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ^Block statement considered harmful for callbacks?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ^Block statement considered harmful for callbacks?


  • Subject: Re: ^Block statement considered harmful for callbacks?
  • From: Oleg Krupnov <email@hidden>
  • Date: Thu, 25 Apr 2013 14:07:10 +0300

The compiler indeed warns, but only for ARC projects, and for non-ARC
projects it perfectly allows blocks to create retain cycles without
any warnings, even Xcode's Analyze doesn't help.

Besides, I'm afraid the compiler is not always capable to detect all
such dangerous situations even with ARC on.

So I am afraid it ends up with lots of retain cycles in virtually
every project that uses blocks, but programmers just don't notice
and/or just don't care. Do you often check your projects for leaks of
this kind? You will be surprised if you do try.

My point remains: blocks are dangerous and there is no easy way to
ensure they are safe. You can't avoid referencing "self" in blocks,
because it is the very point of almost every callback block. So you
have to every time to remind yourself to jump through hoops to avoid
the retain cycles. Nah.



On Thu, Apr 25, 2013 at 1:45 PM, Tom Davie <email@hidden> wrote:
>
> On 25 Apr 2013, at 11:40, Diederik Meijer | Ten Horses <email@hidden> wrote:
>
>> I don't agree, blocks are very powerful.
>>
>> I am using Xcode 4.6 and in a project that uses ARC it was throwing warnings when a block reference to a property caused a retain cycle. This is how I found it and why I mentioned it in another thread in the first place.
>>
>> I haven't tested it extensively, but it looks as if the compiler recognises these situations easily and then tells you about it.
>>
>> So I wouldn't call blocks dangerous at all…
>
> You're right – the compiler *is* detecting some simple cases, as I suggested!  Note – this does not make throwing blocks around without paying attention to retain cycles inherently safe though, the compiler can not statically infer all potential cycles.
>
> Thanks
>
> Tom Davie

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: ^Block statement considered harmful for callbacks?
      • From: Lee Ann Rucker <email@hidden>
    • Re: ^Block statement considered harmful for callbacks?
      • From: Steven Degutis <email@hidden>
References: 
 >^Block statement considered harmful for callbacks? (From: Oleg Krupnov <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Tom Davie <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Oleg Krupnov <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Tom Davie <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Diederik Meijer | Ten Horses <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Tom Davie <email@hidden>)

  • Prev by Date: Re: ^Block statement considered harmful for callbacks?
  • Next by Date: sandboxd deny hid-control weirdness
  • Previous by thread: Re: ^Block statement considered harmful for callbacks?
  • Next by thread: Re: ^Block statement considered harmful for callbacks?
  • Index(es):
    • Date
    • Thread