[swift-users] access violation when weak variable

Mark Dalrymple markd at borkware.com
Sat Jul 9 11:20:16 CDT 2016


The actual death is happening when setting the parent:

do {
    let frank = Person(name: "Frank")
    print("frank\(frank)")
    let lisa = Person(name: "Lisa")
    frank.parent = lisa   // Dies here with EXC_BAD_ACCESS

You can click the eye to get a stack trace. (not included here because of
rdar://27263098 - can't get a copyable stack trace from a hard error in
playgrounds).

My bet it's something playground related - about 9 frames down in the stack
trace has a reference to the Playground Logger doing the Mirror thing.

Putting your code in to a standalone swift executable lets it work.

Cheers,
++md




On Sat, Jul 9, 2016 at 10:18 AM, Ray Fix via swift-users <
swift-users at swift.org> wrote:

>
> Hi!
>
> When I make a variable weak in Xcode 8 (both beta 1 and beta 2) I get a
> access violation.  I think this is a bug, but want to make sure I am not
> missing something.
>
> Best regards,
> Ray
>
> //: Playground - noun: a place where people can play
>
> import UIKit
>
> class Person: CustomStringConvertible {
>     var name: String
>     weak var parent: Person?     /// If I remove weak, no crash in Xcode 8
> beta 2, but leaks
>     var children: [Person] = [] {
>         didSet {
>             children.forEach { $0.parent = self }
>         }
>     }
>
>     init(name: String) {
>         self.name = name
>         print("initialized \(name)")
>     }
>     deinit {
>         print("deinit \(name)")
>     }
>     var description: String {
>         return name
>     }
> }
>
> do {
>     let frank = Person(name: "Frank")
>     let lisa = Person(name: "Lisa")
>     frank.children = [lisa]                   /// KABOOM!
> }
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160709/c0a33bdd/attachment.html>


More information about the swift-users mailing list