• 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: Swift crash in dispatch_apply
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift crash in dispatch_apply


  • Subject: Re: Swift crash in dispatch_apply
  • From: Roland King <email@hidden>
  • Date: Tue, 08 Jul 2014 11:48:44 +0800

I'm talking about the paragraph before that which says

“Define a capture in a closure as an unowned reference when the closure and the instance it captures will always refer to each other, and will always be deallocated at the same time.

Conversely, define a capture as a weak reference when the captured reference may become nil at some point in the future.”

I think your reference became nil at some point or slightly more subtly the underlying NSObject was released after its reference count dropped to nil even if the swift variable still existed in some form. Then when the underlying NSObject was retained at the start of the block code, it crashed resurrecting a zombie object.

What's odd is that changing it to weak didn't make it not print the line, which you'd expect if it were null (at least when I tried it out the other day), it just removed the crash. Hence I suspect you fell over a bug. Have you tried it with Beta 3? I'd still recommend compiling into a piece of code, I'm still getting a lot of playground crashes and finding that a full compile is more stable.

On 8 Jul, 2014, at 11:36 am, Gerriet M. Denkmann <email@hidden> wrote:

>
> On 8 Jul 2014, at 10:03, Roland King <email@hidden> wrote:
>
>>>> Why are you making self unowned?
>>>
>>> I have no idea.
>>> The Swift book (in the chapter "“Resolving Strong Reference Cycles for Closures”) seems to say that this is the correct way to "resolve a strong reference cycle between a closure and a class instance”.
>>
>> Not quite - it says unowned if the block and self have the same lifetime, else weak.
>
> The book says: “If the captured reference will never become nil, it should always be captured as an unowned reference, rather than a weak reference.”
>
> And I can think of no way how "self" = instance of my Crash class could ever become nil while its function makeCrash is running.
>
> Anyway: even without "[unowned self]" I always see a println() inside of deinit{} (if it is not crashing before).
> Which might indicate that there are no evil retain-cycles taking place.
>
>
> Could anybody show me some example which really needs [unowned self] or [weak self] to break a retain-cycle?
>
>
> Kind regards,
>
> Gerriet.
>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Swift crash in dispatch_apply
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >Swift crash in dispatch_apply (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Swift crash in dispatch_apply (From: "Clark S. Cox III" <email@hidden>)
 >Re: Swift crash in dispatch_apply (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Swift crash in dispatch_apply (From: Roland King <email@hidden>)
 >Re: Swift crash in dispatch_apply (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Swift crash in dispatch_apply
  • Next by Date: Can I set build configurations in Swift code?
  • Previous by thread: Re: Swift crash in dispatch_apply
  • Next by thread: Re: Swift crash in dispatch_apply
  • Index(es):
    • Date
    • Thread