Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

garbage collection of WorldObjects #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 13, 2023
Merged

garbage collection of WorldObjects #160

merged 11 commits into from
Apr 13, 2023

Conversation

kushalkolar
Copy link
Member

@kushalkolar kushalkolar commented Apr 3, 2023

Follows up from #159

This implements:

  • A global WORLD_OBJECTS dict in fastplotlib.graphics._base used internally by fastplotlib to keep track of all pygfx WorldObject instances in a session. Graphic instances only use a weak reference proxy to access their WorldObject using their hex id. All references to world objects outside of this dict are via proxies.
  • A global GRAPHICS dict in fastplotlib.layouts._base to keep track of all Graphic objects, functions similar to the global world objects dict. All references to Graphic objects outside of this dict are via proxies. The various plot.add_<graphic> methods only return proxies.

Adds a PlotArea.delete_graphic() method which is the only way that a Graphic should be deleted. This also frees up GPU VRAM.

GPU VRAM freed and tested for:

  • Image

  • Line

  • LineCollection

  • Scatter

  • [ ] Text will do this later once text is more stabilized

  • Heatmap (new one)

  • Modify how LineSlider is added in PlotArea but don't need to check garbage collection since their memory footprint is very small. UPDATE: This isn't necessary, LineSlider continues to work.

RAM freed and tested for:

  • Image
  • Line
  • LineCollection
  • Scatter
  • Heatmap (new one)

@kushalkolar
Copy link
Member Author

GPU VRAM is freed by deleting the WorldObject, we probably need to make weak references to the various feature data to allow RAM to be freed when those are deleted. Maybe by using a similar dict to keep data, COLOR_FEATURE, DATA_FEATURE.

@kushalkolar
Copy link
Member Author

GPU VRAM get freed perfectly.

System RAM gets cleared to an extent, it doesn't keep growing which is the most important thing. There must be a lingering reference because we create data array in jupyter, and this is the data that we feed to add_<graphic>. But since it doesn't keep growing I think it's fine for now.

fastplotlib/graphics/_base.py Show resolved Hide resolved
fastplotlib/graphics/_base.py Show resolved Hide resolved
fastplotlib/graphics/image.py Show resolved Hide resolved
@kushalkolar kushalkolar merged commit c9c6c78 into master Apr 13, 2023
@kushalkolar kushalkolar deleted the better-gc branch May 23, 2023 04:47
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.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.