# Clarification about memory management of immutable and mutable struct

**URL:** <https://discourse.julialang.org/t/clarification-about-memory-management-of-immutable-and-mutable-struct/31064>\
**Category:** Internals & Design\
**Tags:** data\_structures\
**Created:** [November 13, 2019, 10:23pm UTC](https://discourse.julialang.org/t/clarification-about-memory-management-of-immutable-and-mutable-struct/31064 "2019-11-13T22:23:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![louisponet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/louisponet/32/2070_2.png) [@louisponet](https://discourse.julialang.org/u/louisponet)\
**Post date:** [November 14, 2019, 12:31am UTC](https://discourse.julialang.org/t/clarification-about-memory-management-of-immutable-and-mutable-struct/31064/3 "2019-11-14T00:31:06Z")

</div>

As soon as you have mutable fields in your immutable it will be heap allocated, at that point you can check for yourself what’s going on as you pass it through functions by looking at pointers I think. `Base.pointer_from_objref` should help you out.

From what I understand everything that’s always allocated on the heap will be passed as a reference rather than by value, since how would it know exactly how to make those copies. Please correct me if I’m wrong, this is partly from my own experience testing some behavior that was discussed here: [Memory layout of structs with mutable fields](https://discourse.julialang.org/t/memory-layout-of-structs-with-mutable-fields/21400).

---

_[View the full topic](https://discourse.julialang.org/t/clarification-about-memory-management-of-immutable-and-mutable-struct/31064)._
