-
Notifications
You must be signed in to change notification settings - Fork 564
Enums accessed from Swift from a non-main thread crash #3353
Comments
With #3368 there's API to hide memory leak related crashes, as needed. |
I'm rebuilding master and will try to repro with the memory checker off. Is this also something that will be fixed, or do we just need to disable memory checking? This is a pretty obscure bud to figure out. |
I understand this better now! The reason the memory check happens is because it's the last memory cleanup Setting In Kotlin: fun touch(){} In Swift: func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SampleKt.touch()
DispatchQueue.global(qos: .background).async { // sends registration to background queue
let ee = Hey.b
print("Hey \(ee)")
}
return true
} It does seem like the objc interop is allocating something to generate the enums, which does seem like it shouldn't count towards "allocation" and memory leaks, but I don't really understand how that process works for interop. |
@olonho will this API make it into 1.3.60? |
Fixed in 1.4.30 with #4482. |
Update: the crash is fixed, but it is still recommended to "touch" Kotlin in the main thread. |
If you access an enum initially from Swift (and presumably Objc), from a non-main thread, and you got there by way of gcd, you will likely get a crash when that thread shuts down.
If you access any part of that enum from the main thread prior, this does not happen. Also, accessing from kotlin and using a Worker, this does not appear to happen.
I've tested this on 1.3.50 and master commit
d153f21d5fbf6e375a4f1dbaaf86d30cc51131c7
, which is almost head of master. I could not trigger the same issue on 1.3.41 or 1.3.30.In kotlin from
commonMain
In Swift
Console
Stack
Presumably
onThreadExitCallback
is called as that thread is shut down, and there's something off about how the enum is accessed and counted.Accessing the enum in the main thread appears to prevent the issue.
Repro code: https://github.com/touchlab/KNEnumCrash
The crash will not happen every time, just fyi. Generally a little better than 50/50.
The text was updated successfully, but these errors were encountered: