First just to clearify no there’s no variable
x being allocated. In julia variable does NOT equal to objects. All what variable (global or local) can do are referring to objects.
Because of/related to this, all objects that you are allowed to take address of are semantically allocated on the heap. You are not allowed to take address of
isbits objects so semantically it doesn’t make sense to talk about where they are allocated (because they are never allocated in any visible way).
As long as the semantic above is maintained, the runtime/compilier can do whatever optimization it wants. It is allowed to stack allocate anything as long as it can proof the user won’t notice. It can remove the construction/allocation of an object altogether if there’s no use of it. This obviously requires a definition for what’s observable and one of them is that global bindings escapes an objects so any
!isbits values (objects) you stored to global variable will be allocated on the heap.
In the case you have above, the string will be allocated on the heap because,
String is never
- All objects binded to global variables are allocated on the heap even though nothing requires
isbits values to do that.
P.S. please quote your code.