On Sun, Feb 7, 2016 at 9:39 AM, Cedric St-Jean <cedric.stj...@gmail.com> wrote: > There's an issue on Github to add GC support for stack-allocated objects, > and that makes no sense to me! Could someone please help me out? In my mind, > stack-allocated objects = Int+Float+...+Immutable (in some circumstances). I > thought that with Immutables, if I have
by `Int + Float + ...` I think you mean bitstype. > > immutable ImagePos > img::Image > x::Int > y::Int > end > > function blah(img) > a = ImagePos(img, 10, 20) > foo(a) > l = Any[40, a] > end > > then `a` is stack-allocated. The foo(a) call may either copy `a` further, or > just pass on a stack pointer to the existing `a`, depending on compiler Right > details. Any stack-allocated object gets automatically wiped as the stack > unwinds, hence does not need GC'ing. s/GC/root/ might be a better word. > > Then on the `l` line, because it's an Any array, the ImagePos needs to be > copied, boxed and heap-allocated. So that one needs GC. I'm not really sure what you mean by `needs GC` here. What will happen is that the element of a `Any` array will be heap(GC) allocated (boxed) and so is the Array l itself. Therefore, `l` wiill be GC rooted and elements in the `l` array are reachable by the GC from the array `l`. > > What did I miss? > > Cédric