I'm not certain this is correct, but here's my understanding: `a = 
ImagePos(img, 10, 20)` absolutely must protect `img` from being GCed in code 
like this:

    function foo()
        img = rand(5,5)
        return ImagePos(img, 10, 20)
    end

But currently objects on the heap do not seem to protect stack-allocated 
objects from being GCed. So, the current choice is stack-allocate all(?) 
immutables that are non-bitstypes, just to make sure we adequately protect 
objects from being GCed. IICU, the new PR adds the ability to support 
protection from heap-allocated objects, which means that it will no longer be 
necessary to stack-allocate non-bitstypes immutables.

Best,
--Tim

On Sunday, February 07, 2016 06:39:51 AM Cedric St-Jean wrote:
> There's an issue <https://github.com/JuliaLang/julia/pull/12205> 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
> 
> 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
> details. Any stack-allocated object gets automatically wiped as the stack
> unwinds, hence does not need GC'ing.
> 
> 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.
> 
> What did I miss?
> 
> Cédric

Reply via email to