# Makie - What could be holding references to plots after I empty! an axis?

**URL:** <https://discourse.julialang.org/t/makie-what-could-be-holding-references-to-plots-after-i-empty-an-axis/118913>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [September 1, 2024, 9:39pm UTC](https://discourse.julialang.org/t/makie-what-could-be-holding-references-to-plots-after-i-empty-an-axis/118913 "2024-09-01T21:39:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AMB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amb/32/211738_2.png) [@AMB](https://discourse.julialang.org/u/AMB)\
**Post date:** [September 1, 2024, 9:39pm UTC](https://discourse.julialang.org/t/makie-what-could-be-holding-references-to-plots-after-i-empty-an-axis/118913/1 "2024-09-01T21:39:45Z")

</div>

Hi all!

I am using GeoMakie and GeoAxis, in case that makes any difference. My application creates a series of visualizations on the GeoAxis, one at a time. When the user indicates that they want the next visualization, I empty! the geoaxis and then draw the next visualization on the same axis.

The problem is that garbage collection is not happening for all of the plots that are empty!ed. Visually speaking, everything is gone and everything _looks_ right, but I believe that the following is happening:

MakieCore plots (like those created by scatter!, text!, etc) are being garbage collected after empty!, as expected. However, plots that don’t seem to be implemented in MakieCore (like those created by contour!) are not being collected. I noticed this because my calls to contour! involve large matrices so I am rapidly running out of memory as those plots apparently “leak”. I added finalizers to the various plots and I can see them being called for MakieCore plots but not for the others.

Are the non-MakieCore plots perhaps being referenced by something else that I’m not aware of? In addition to empty!ing the axis, I’m also clearing the connect!ions to them, so that’s not it. I don’t hold any references to the plots in my application after they’re created and connect!ed.

On a tangent… I haven’t delved into the “recipe” functionality of Makie, but are things like contour! an example of a recipe?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [September 2, 2024, 6:18am UTC](https://discourse.julialang.org/t/makie-what-could-be-holding-references-to-plots-after-i-empty-an-axis/118913/2 "2024-09-02T06:18:11Z")

</div>

Please open an issue on github with an example where you reduce the case that leaks memory as much as possible. It’s interesting that it doesn’t seem to happen for primitives, maybe that’s a good hint what machinery to look into. `empty!` shouldn’t leak, but we don’t really have the best tests for this kind of thing, yet.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 2, 2024, 9:45am UTC](https://discourse.julialang.org/t/makie-what-could-be-holding-references-to-plots-after-i-empty-an-axis/118913/3 "2024-09-02T09:45:20Z")

</div>

It could be that the core plots are simply better tested for leaks… So an issue with mwe would be great!

---

<div class="post-metadata">

**Author:** ![AMB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amb/32/211738_2.png) [@AMB](https://discourse.julialang.org/u/AMB)\
**Post date:** [September 2, 2024, 7:32pm UTC](https://discourse.julialang.org/t/makie-what-could-be-holding-references-to-plots-after-i-empty-an-axis/118913/4 "2024-09-02T19:32:03Z")

</div>

Thanks for the replies. See [Memory associated only with non-primitive plots is not garbage collected after empty!(axis) · Issue #4302 · MakieOrg/Makie.jl · GitHub](https://github.com/MakieOrg/Makie.jl/issues/4302)
