Re: Swift crash in dispatch_apply
Re: Swift crash in dispatch_apply
- Subject: Re: Swift crash in dispatch_apply
- From: "Clark S. Cox III" <email@hidden>
- Date: Mon, 07 Jul 2014 10:00:19 -0700
> On Jul 4, 2014, at 23:05, Gerriet M. Denkmann <email@hidden> wrote:
>
> Why does this crash?
>
> class Crash : NSObject // must be subclass of NSObject to get a crash
> {
> var globalSize = 0
> let queue = dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 )
>
> func makeCrash()
> {
> globalSize = 97 // anything
> let nbrThreads : UInt = 1 // any positive number will do; output might be garbled for > 1
> let localSize = globalSize
>
> println("makeCrash will do dispatch_apply( \(nbrThreads) )")
> dispatch_apply( nbrThreads, queue,
> { [unowned self] (idx: size_t) in
>
> println( "thread[\(idx)] local \(localSize)") // ok
>
> // next line will crash --- Mac OS X 10.9.4 Xcode Version 6.0 (6A216f)
> println( "thread[\(idx)] global \(self.globalSize)") // will crash
> }
> )
> }
> }
>
> let dummy = Crash()
> dummy.makeCrash()
What is the actual crash?
> What am I doing wrong?
Why are you making self unowned? I suspect (without seeing the actual crash) that dummy has been released as there are no more strong references to it.
_______________________________________________
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