Garbage collector freeing rooted data?

Hi, last weekend I tried to use Plots/PyPlot when embedding Julia. I’ve written a function that takes a plot function and an arbitrary number of (keyword) arguments, which simply calls the given function with the provided arguments and then adds a callback to the window that notifies an Event when it has been closed. The function returns the plot and the mentioned Event.

After returning, the result is immediately rooted. Despite this, if I call the function a second time to show another figure the previous result is freed unless I ensure it’s globally rooted before returning (e.g. by placing it in a global Dict and removing it in the close-callback). The return value must also be a mutable struct, otherwise it’s still freed after the second call.

I’ve built a debug version of Julia to which I’ve added some additional logging to the mark loop in order to check if the frame in which the result is rooted is skipped for some reason, but that’s not the case. The mark loop visits this frame, and tries to mark the rooted object. The function gc_try_setmark does return 0, but the tag seems to be 1 already, indicating that the object should young and reachable.

Has anyone else experienced issues like this?