# Tell me about escape analysis and optimizing heap allocations

**URL:** <https://discourse.julialang.org/t/tell-me-about-escape-analysis-and-optimizing-heap-allocations/92658>\
**Category:** Internals & Design\
**Created:** [January 8, 2023, 6:47am UTC](https://discourse.julialang.org/t/tell-me-about-escape-analysis-and-optimizing-heap-allocations/92658 "2023-01-08T06:47:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 9, 2023, 2:02am UTC](https://discourse.julialang.org/t/tell-me-about-escape-analysis-and-optimizing-heap-allocations/92658/2 "2023-01-09T02:02:05Z")

</div>

I did an exploration here where I tried to see if I could get a finalizer that frees a pointer to inline.

> [@Eager finalization and smart pointers](https://discourse.julialang.org/t/eager-finalization-and-smart-pointers/92462/2):
>
> Digging deeper, it seems it may be too early to pursue this since there are significant restrictions in terms of what kind of finalizers can be called eagerly. Following @aviatesk 's demonstration, it is still quite impressive how well this works. using Test include(normpath(Sys.BINDIR, "..", "share", "julia", "test", "compiler", "EscapeAnalysis", "setup.jl")) const FINALIZATION\_COUNT = Ref(0) init\_finalization\_count!() = FINALIZATION\_COUNT[] = 0 get\_finalization\_count() = FINALIZATION\_COUNT[…

I made some progress. If I do nothing with the smart pointer, it gets deallocated.

---

_[View the full topic](https://discourse.julialang.org/t/tell-me-about-escape-analysis-and-optimizing-heap-allocations/92658)._
