Skip to content

Commit 7e087db

Browse files
committed
gc works for Line, LineCollection, Scatter not tested, regular RAM is not gc, WIP
1 parent 8ffab35 commit 7e087db

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

fastplotlib/graphics/line.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ def __init__(
8585

8686
self.thickness = ThicknessFeature(self, thickness)
8787

88-
self._world_object: pygfx.Line = pygfx.Line(
88+
world_object: pygfx.Line = pygfx.Line(
8989
# self.data.feature_data because data is a Buffer
9090
geometry=pygfx.Geometry(positions=self.data(), colors=self.colors()),
9191
material=material(thickness=self.thickness(), vertex_colors=True)
9292
)
9393

94+
self._set_world_object(world_object)
95+
9496
if z_position is not None:
9597
self.world_object.position.z = z_position
9698

fastplotlib/graphics/line_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(
157157
"or must be a str of tuple/list with the same length as the data"
158158
)
159159

160-
self._world_object = pygfx.Group()
160+
self._set_world_object(pygfx.Group())
161161

162162
for i, d in enumerate(data):
163163
if isinstance(z_position, list):

fastplotlib/graphics/scatter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ def __init__(
7272

7373
super(ScatterGraphic, self).__init__(*args, **kwargs)
7474

75-
self._world_object: pygfx.Points = pygfx.Points(
75+
world_object = pygfx.Points(
7676
pygfx.Geometry(positions=self.data(), sizes=sizes, colors=self.colors()),
7777
material=pygfx.PointsMaterial(vertex_colors=True, vertex_sizes=True)
7878
)
7979

80+
self._set_world_object(world_object)
81+
8082
self.world_object.position.z = z_position

fastplotlib/layouts/_base.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Viewport, WgpuRenderer
44
from wgpu.gui.auto import WgpuCanvas
55
from warnings import warn
6-
from ..graphics._base import Graphic, WORLD_OBJECTS
6+
from ..graphics._base import Graphic, GraphicCollection, WORLD_OBJECTS
77
from ..graphics.line_slider import LineSlider
88
from typing import *
99

@@ -319,8 +319,18 @@ def delete_graphic(self, graphic: Graphic):
319319

320320
self._graphics.remove(graphic)
321321

322-
# delete associated world object to free GPU VRAM
322+
# for GraphicCollection objects
323+
if isinstance(graphic, GraphicCollection):
324+
# clear Group
325+
graphic.world_object.clear()
326+
# delete all child world objects in the collection
327+
for g in graphic.graphics:
328+
subloc = hex(id(g))
329+
del WORLD_OBJECTS[subloc]
330+
331+
# get mem location of graphic
323332
loc = hex(id(graphic))
333+
# delete world object
324334
del WORLD_OBJECTS[loc]
325335

326336
del graphic

0 commit comments

Comments
 (0)