fastplotlib / fastplotlib

Next-gen fast plotting library running on WGPU using the pygfx rendering engine
https://fastplotlib.readthedocs.io/
Apache License 2.0
342 stars 33 forks source link

Know when a jupyter cell output has been "overwritten" #470

Open kushalkolar opened 2 months ago

kushalkolar commented 2 months ago

I wonder if it's possible to know when a cell with a plot in the output has been replaced by running the cell again, I think the previous plot(s) still linger in RAM when this happens. I wonder if there's a way in juptyer to capture that a cell has been overwritten so we can close a plot if it's in the output.

almarklein commented 2 months ago

I just tried running this code in a cell repeatedly:

class Foo:
    def __del__(self):
        print(f"foo {id(self)} is deleted")

Foo()

Contrary to my assumptions, I do not see the message being printed (It is when I write foo = Foo() instead, so it's not actually the cell output). Wtf.

kushalkolar commented 2 months ago

Yea I will need to investigate this later, jupyter gc, part 3 :laughing:

Edit: maybe some ideas here to reset the output https://stackoverflow.com/questions/49515085/python-garbage-collection-sometimes-not-working-in-jupyter-notebook