• 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: "Clark S. Cox III" <email@hidden>
  • Date: Tue, 08 Jul 2014 10:19:24 -0700


On Jul 8, 2014, at 10:03, Gerriet M. Denkmann <email@hidden> wrote:


On 8 Jul 2014, at 23:12, Clark S. Cox III <email@hidden> wrote:


On Jul 7, 2014, at 22:10, Gerriet M. Denkmann <email@hidden> wrote:


On 8 Jul 2014, at 10:57, Clark S. Cox III <email@hidden> wrote:


On Jul 7, 2014, at 20:36, 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.

Believe me, it can. Nothing after that point has a strong reference to self (because the only remaining reference to self is inside of the closure, but you made that particular reference “unowned”), the compiler is free to release it after the closure is created, but before dispatch_apply is called.

But the caller of makeCrash has a strong reference to self via
let dummy = Crash()
does this not keep the instance of Crash alive?

No, because the compiler can see that dummy is never used again after the call to makeCrash.

So I changed the call to:

println("will try makeCrash")
let dummy = Crash()
dummy.makeCrash()
println("makeCrash did NOT crash status: " + dummy.status )

But it still crashes.

Then that seems like a bug to me. i would recommend reporting it.

If, in makeCrash, you used self after the dispatch_apply, then the compiler would see that it still has a reference and self would still exist.

So I changed this to
dispatch_apply( nbrThreads, queue, ...
println("makeCrash did do dispatch_apply without crashing")

But it still crashes.

That line doesn’t use self.


 _______________________________________________
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

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>)
 >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: "Clark S. Cox III" <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: Re: Sudden provisioning profile issues
  • Previous by thread: Re: Swift crash in dispatch_apply
  • Next by thread: Is Swift really swift?
  • Index(es):
    • Date
    • Thread