Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unowned references #5

Merged
merged 1 commit into from
Jul 7, 2014
Merged

Added unowned references #5

merged 1 commit into from
Jul 7, 2014

Conversation

ashfurrow
Copy link
Contributor

No description provided.

ksm pushed a commit that referenced this pull request Jul 7, 2014
Added unowned references
@ksm ksm merged commit d6d527c into ksm:master Jul 7, 2014
@ksm
Copy link
Owner

ksm commented Jul 7, 2014

Thanks Ash. 👍

@ksm
Copy link
Owner

ksm commented Jul 8, 2014

@ashfurrow was this solved with beta 3?

@ashfurrow
Copy link
Contributor Author

Checking now.

@ashfurrow
Copy link
Contributor Author

Nope – still exists.

@RuiAAPeres
Copy link

@ashfurrow does that exact example still breaks, or is your example (radar one) that still fails?

@ashfurrow
Copy link
Contributor Author

Yup still crashing on both. For example:

protocol MyProtocol: NSObjectProtocol {
    func method()
}

class MyObject : NSObject {
    unowned let delegate: MyProtocol

    init(delegate: MyProtocol) {
        self.delegate = delegate
        super.init()
    }

    func doSomethingWithDelegate() {
        delegate.method()
    }
}

class DelegateClass: NSObject, MyProtocol {
    func method () {
        for i in 1...10 {
            "Hello!"
        }
    }
}

And later...

let delegate = DelegateClass()
let object = MyObject(delegate: delegate)

object.doSomethingWithDelegate()
println("\(delegate)") // keep it from being released

New stack trace though:

* thread #1: tid = 0x985d15, 0x0028cd60 libswift_stdlib_core.dylib`_swift_release_slow, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
  * frame #0: 0x0028cd60 libswift_stdlib_core.dylib`_swift_release_slow
    frame #1: 0xbff2cf88
    frame #2: 0x00298cbe libswift_stdlib_core.dylib`swift_unknownRetainUnowned + 318
    frame #3: 0x000d332f Bug`Bug.MyObject.delegate.getter : @unowned Bug.MyProtocol(self=0x7d13ab30) + 47 at AppDelegate.swift:0
    frame #4: 0x000d322b Bug`Bug.MyObject.doSomethingWithDelegate (self=0x7d13ab30)() -> () + 43 at AppDelegate.swift:25
    frame #5: 0x000d3282 Bug`@objc Bug.MyObject.doSomethingWithDelegate (Bug.MyObject)() -> () + 34 at AppDelegate.swift:0
    frame #6: 0x000d3ab2 Bug`Bug.AppDelegate.application (application=0x7d536080, launchOptions=None, self=0x7be42f90)(ObjectiveC.UIApplication, didFinishLaunchingWithOptions : Swift.Optional<ObjectiveC.NSDictionary>) -> Swift.Bool + 146 at AppDelegate.swift:50
    frame #7: 0x000d3cc5 Bug`@objc Bug.AppDelegate.application (Bug.AppDelegate)(ObjectiveC.UIApplication, didFinishLaunchingWithOptions : Swift.Optional<ObjectiveC.NSDictionary>) -> Swift.Bool + 101 at AppDelegate.swift:0
    frame #8: 0x00d27feb UIKit`-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 291
    frame #9: 0x00d28d29 UIKit`-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2920
    frame #10: 0x00d2befb UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1507
    frame #11: 0x00d44742 UIKit`__84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
    frame #12: 0x00d2ac3e UIKit`-[UIApplication workspaceDidEndTransaction:] + 29
    frame #13: 0x0351bbce FrontBoardServices`__37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 43
    frame #14: 0x0351b834 FrontBoardServices`__40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
    frame #15: 0x0352d455 FrontBoardServices`__31-[FBSSerialQueue performAsync:]_block_invoke + 26
    frame #16: 0x0044e540 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
    frame #17: 0x004437d3 CoreFoundation`__CFRunLoopDoBlocks + 195
    frame #18: 0x0044362b CoreFoundation`__CFRunLoopRun + 2715
    frame #19: 0x004428cb CoreFoundation`CFRunLoopRunSpecific + 443
    frame #20: 0x004426fb CoreFoundation`CFRunLoopRunInMode + 123
    frame #21: 0x00d2a555 UIKit`-[UIApplication _run] + 571
    frame #22: 0x00d2dba5 UIKit`UIApplicationMain + 1526
    frame #23: 0x000d40a1 Bug`top_level_code + 97 at AppDelegate.swift:39
    frame #24: 0x000d40db Bug`main + 43 at AppDelegate.swift:0
    frame #25: 0x023acac9 libdyld.dylib`start + 1

@RuiAAPeres
Copy link

@ashfurrow 👍

@jckarter
Copy link

@ashfurrow It looks like the object is getting released before the unowned access, though it shouldn't in this case. Do you have a radar for this? This is a good test case.

@ashfurrow
Copy link
Contributor Author

Yes, I've filed a radar.

@jeremy-w
Copy link

Huh. This seems similar to the sort of problems solved by the objc_precise_lifetime attribute in Obj-C-ARC-land. Only Swift doesn't seem to expose any attribute like that for its ARC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants