# Simulate manual memory management to reduce RAM usage?

**URL:** <https://discourse.julialang.org/t/simulate-manual-memory-management-to-reduce-ram-usage/67281>\
**Category:** General Usage\
**Tags:** garbage-collection\
**Created:** [August 29, 2021, 12:38pm UTC](https://discourse.julialang.org/t/simulate-manual-memory-management-to-reduce-ram-usage/67281 "2021-08-29T12:38:39Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 12, 2022, 10:32pm UTC](https://discourse.julialang.org/t/simulate-manual-memory-management-to-reduce-ram-usage/67281/3 "2022-11-12T22:32:59Z")

</div>

> [@greatpet](#):
>
> for heap-allocated local objects that do **not** “escape” the function (e.g. returned or passed to another function), is it possible for Julia’s compiler to deallocate the memory as soon as the object is out of scope

Yes, there’s a brand-new package for that, see at:

> [@Avoiding allocations of small but non-trivial arrays (work array alternative?)](https://discourse.julialang.org/t/avoiding-allocations-of-small-but-non-trivial-arrays-work-array-alternative/90084/10):
>
> There’s a brand new package that seems like made for you. It’s probably not yet registered (you can still use/try it), nor announced: In theory Julia could heap-allocate for you and free before exit of barw\_array, but it would be slower. Or allocate on the stack, but it’s limited so dangerous, you don’t know how large the array is going to be, so I doubt that’s a better policy (or check at runtime the size and only stack-allocate if small).

I would try it (in about a week, in case there are bugs). It’s not just for small objects. It’s faster, but actually doesn’t reduce “RAM usage”, just allocation overhead.

---

_[View the full topic](https://discourse.julialang.org/t/simulate-manual-memory-management-to-reduce-ram-usage/67281)._
