Description
I figured it's useful to have this in an issue and publicly as well.
We return weakref.proxy objects to the real Graphic
objects so that jupyter doesn't accumulate references when the user uses references to the Graphic.
Almar's description:
The problem is that it may confuse the user (it shows “proxy” in the repr) and it results in a rather unconventional memory management system.
I’ve looked into at least changing the repr, but this is not possible. We’ve discussed the reasons underlying the choice, coming mostly down to event handlers holding onto objects. This is a tricky problem, and there is not a simply solution that will make it go away.
We’ve concluded that the current solution does the job. Since these proxy objects look a lot like the real objects, the burden on the user is not too bad. And if the approach is changed in the future, this will most likely not affect users code.
On the longer term, I think it might be worth looking into a way to clear handlers. This should also be done in pygfx’ world objects. Then when a plot is cleared, it can also clear/destroy all graphics objects within.
I just wanted to add, I think the one issue with proxies is that they are not hashable, so they cannot be used as dict keys.
Anyways, not something we will work on now, but #467 helps make this all cleaner internally.