# When embedding, do jl\_array\_t\*, jl\_sym\_t\* and jl\_value\_t\*-representing-a-type need to be wrapped in RefValue{Any} when rooting?

**URL:** <https://discourse.julialang.org/t/when-embedding-do-jl-array-t-jl-sym-t-and-jl-value-t-representing-a-type-need-to-be-wrapped-in-refvalue-any-when-rooting/28896>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 18, 2019, 2:46pm UTC](https://discourse.julialang.org/t/when-embedding-do-jl-array-t-jl-sym-t-and-jl-value-t-representing-a-type-need-to-be-wrapped-in-refvalue-any-when-rooting/28896 "2019-09-18T14:46:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JJB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jjb/32/6773_2.png) [@JJB](https://discourse.julialang.org/u/JJB)\
**Post date:** [September 18, 2019, 2:46pm UTC](https://discourse.julialang.org/t/when-embedding-do-jl-array-t-jl-sym-t-and-jl-value-t-representing-a-type-need-to-be-wrapped-in-refvalue-any-when-rooting/28896/1 "2019-09-18T14:46:52Z")

</div>

From [Embedding Julia · The Julia Language](https://docs.julialang.org/en/v1/manual/embedding/), it seems if I want a long-lasting object not to be collected by the Julia garbage collector when embedding Julia in C++, I need to store that object in an IdDict bound to a global Julia variable. If the object is immutable, then I can’t just store it directly, I need to wrap it in a RefValue{Any}. My question is:

1. Does a jl\_array\_t\* created by jl\_ptr\_to\_array\_1d also need to be wrapped in a RefValue{Any} when the element type is immutable?
2. Does a jl\_sym\_t\* need to be wrapped in a RefValue{Any}?
3. Does a jl\_value\_t\* that points to a type (e.g. jl\_eval\_string(“MyType”)) need to be wrapped in a RefValue{Any}?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 18, 2019, 3:17pm UTC](https://discourse.julialang.org/t/when-embedding-do-jl-array-t-jl-sym-t-and-jl-value-t-representing-a-type-need-to-be-wrapped-in-refvalue-any-when-rooting/28896/2 "2019-09-18T15:17:53Z")

</div>

As mensioned in the document, this only apply to immutable types and you can answer this yourself,

```julia
julia> isimmutable([1, 2])
false

julia> isimmutable(:a)
false

julia> struct MyType
       end

julia> isimmutable(MyType)
false

```

---

<div class="post-metadata">

**Author:** ![JJB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jjb/32/6773_2.png) [@JJB](https://discourse.julialang.org/u/JJB)\
**Post date:** [September 19, 2019, 2:09pm UTC](https://discourse.julialang.org/t/when-embedding-do-jl-array-t-jl-sym-t-and-jl-value-t-representing-a-type-need-to-be-wrapped-in-refvalue-any-when-rooting/28896/3 "2019-09-19T14:09:09Z")

</div>

Thanks for explaining!
