-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[ARC] {.global.}
pragma doesn't work when the variable is initialized with non-value types
#17552
Comments
Also, what are the alternatives to the |
I really hope and think this is not true:
In the last 12 months I had the feeling that gintro was working fine with ARC. Well minor memory leaks may exists, it is hard to debug leaks with gtk as gtk has itself behaviour which may looks like leaks in valgrind. I hope I will get my CDT to work with ARC at all :-) |
@StefanSalewski are those "value types" from the Nim perspective? If they're simple raw pointers or ints/bools/etc, they'll work fine. |
Sorry, forget to mention:
Most are ref objects. The cairo.Context is used a lot in the draw callback! We get from the cairo lib the low level object only but need the Nim proxy object for the actual drawing code, so we use global pragma to have an instance of the proxy object available for each callback call. New allocation for each call would be not that nice, may work with ARC, but with default GC delayed deallocation can be a problem. It was a problem for Ruby ten years ago. |
{.global.}
pragma doesn't work with non-value types {.global.}
pragma doesn't work when the variable is initialized with non-value types
Update - global pragma actually works if we separate declaration and initialization |
As much as I dislike .global, we can also just fix the bug. |
The title says it all, with ARC
{.global.}
only seems to work with value types (ints, bools, objects) or when declaration and Initialization of the global variable are separate.Non-value types (ref objects, strings, and other types that are managed by the runtime) are always initialized each time if they have are declared with an assignment. Found out by investigating memory leak in https://forum.nim-lang.org/t/7709.
Example
Current Output
ARC/ORC:
refc:
On the contrary, this works just fine:
I think that the compiler should show a warning when
{.global.}
pragma is used with ARC/ORC, or at least when it's used with non-value types. Or we can deprecate it altogetherAdditional Information
This might be related to #15005.
The text was updated successfully, but these errors were encountered: