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
x/mobile/bind: static variables in iOS/Swift aren't reference counted correctly #12859
Comments
@scisci thanks for the report. I tried to reproduce it based on the code snippet you included, but couldn't reproduce the crash. |
Yep, will do. The bug showed up in a larger project, and the example above I just wrote in here to demonstrate, so it may very well need some better modelling. I will have to break it out which might take a minute. I'll let you know. |
Hi @hyangah, here is a test project that demonstrates the error: https://github.com/scisci/gomobile-static-test /lib holds the golang library (please note I've converted it to a Module so it can be imported by swift after the build process, so you have to do that manually if you want to rebuild it) Crash Report:
|
Thanks @scisci. The xcode project complains it couldn't find the module Lib (yeah, I see the xcodeproj has a link to your directory :-) I just rebuilt the framework using the build-lib.sh there. FYI, the current version of gomobile bind produces the module map, so you don't have to manually tweak the framework for use in swift any more. And with iPhone6 simulator (iOS8.4), I couldn't reproduce the crash. From your crash log, I guess you also tried with a simulator. I am puzzled. Which version of go, and gomobile did you use? Does the problem still exist when you try with the tip? |
Thanks @hyangah, my gomobile version is +9e2ad8c, I will try to update and see if it changes. Just a question, did you hit the button twice in your tests? It is required to produce the crash. |
hey @hyangah, indeed updating to the latest version of gomobile has solved the issue. thanks! |
When I declare a variable statically like this:
I can call SwiftClass.sharedInstance.doSomething();
It works the first time, but if I call it at some later time, it crashes in the reference counting area of the go library. I think this must be because go doesn't understand that the member of the static variable shouldn't be garbage collected. I was able to get around the issue by not declaring my singleton as static, and instead just declaring it as a global variable.
The text was updated successfully, but these errors were encountered: