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

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?

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.

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

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