Skip to content

Conversation

JamesWrigley
Copy link
Member

@FaresX, any opinions on 86ddf0a? I'm a little torn about the internal state thing since it doesn't really match ImGui style. On the other hand I want it to be possible for people who don't dynamically create many plots (which I'm guessing is a majority) to show them with minimal hassle.

@JamesWrigley JamesWrigley self-assigned this Mar 16, 2025
@JamesWrigley JamesWrigley linked an issue Mar 16, 2025 that may be closed by this pull request
@FaresX
Copy link

FaresX commented Mar 19, 2025

If concerned about deviating from ImGui's style, you could avoid explicitly exposing a delete_figure! method. However, whether using the figure itself as a key or an ID as a key, the originally passed figure would persist - though this allows new figures to be passed in, unlike previous implementations. Alternatively, we could maintain the ImGuiID approach: during each frame, compare whether the incoming figure matches the figure associated with its ID. If they differ, refresh the makie_context while purging the original figure. This ensures that even with repeated new figure submissions, the makie_context's memory footprint won't grow indefinitely.

if !haskey(makie_context, id) || f != makie_context[id]
   
    f != makie_context[id] && delete_figure!(makie_context[id])
    

    window = ig.current_window()
    makie_window = ImMakieWindow(window)
    screen = GLMakie.Screen(; window=makie_window, start_renderloop=false)

    makie_context[id] = ImMakieFigure(f, screen)
    scene = Makie.get_scene(f)
    scene.events.window_open[] = true
    display(screen, f)
end

@JamesWrigley
Copy link
Member Author

JamesWrigley commented Mar 19, 2025

Alternatively, we could maintain the ImGuiID approach: during each frame, compare whether the incoming figure matches the figure associated with its ID. If they differ, refresh the makie_context while purging the original figure. This ensures that even with repeated new figure submissions, the makie_context's memory footprint won't grow indefinitely.

Hmmm that was my original plan but I decided against it for some reason. But now I can't remember why 🙃 I'll think it over, if it works then yeah let's do that.

EDIT: now I remember, to do this garbage collection automatically we still need to figure out if a user wants to display the same figure again. Which we can't know in general since users may create an arbitrary number of figures with arbitrary IDs.

@FaresX
Copy link

FaresX commented Mar 19, 2025

I think we can simply remove the figure from makie_context without actively purging its contents. If users require garbage collection, they can handle it within their own context stack, without worrying about lingering internal references preventing proper cleanup - since the detachment ensures no internal retention would block resource release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is there any way to delete a figure in the makie_context?

2 participants