Will new local class instance be garbage collected if I return an array it creates? <p>Let's say a class instance will build arrays:</p> <pre><code>class FooArrBuilder { public Foo[] FinalResult { get { return arr; } } Foo[] arr; public void BuildArr(); ... } </code></pre> <p>Then it's used like this:</p> <pre><code>Foo[] GetFooArr() { var fb = new FooArrBuilder(); fb.BuildArr(); ... return fb.FinalResult; } </code></pre> <p>When an array is built inside an instance local to a function, will the array be moved out of the instance that built it, or will the whole instance be kept in memory just to contain the array? I do not necessarily want to copy the array if the latter is the case - but maybe I could make the class a struct? Help is appreciated :)</p> <p>If you care to elaborate a bit on C#'s memory model here, it would probably help me to avoid further confusion as well.</p> <p>Thanks in advance</p>