-
My Improvement I was digging through the documentation but I could not find a clear statement: Can textures be unloaded? I.e. can I free their memory and remove them from a texture registry? If yes, how? I am considering to use DearPyGui for an app that would dynamically load and visualize a large quantity of images, likely exceeding available memory, so a clean way of managing memory is highly desired. Necessary Assets None. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You just need to "delete_item(...)". This will remove them from the texture registry. Once the last item using the texture is deleted, it will unload the texture completely. |
Beta Was this translation helpful? Give feedback.
-
@hoffstadt Is this the way to free the texture memory class ImageDraw:
def __init__(self,
width: int = 2000,
height: int = 1000,
border: bool = False,
no_scrollbar: bool = True):
assert (width > 0), 'width>0 for ImageDraw'
assert (height > 0), 'height>0 for ImageDraw'
self.imgdraw_tag: int = dpg.generate_uuid()
gap: int = 15
self.img_w: int = width - gap
self.img_h: int = height - gap
with dpg.window(width=width,
height=height,
tag=self.imgdraw_tag,
no_scrollbar=no_scrollbar):
dpg.add_button(label='delete', callback=self.__del__)
self.texture_tag = dpg.generate_uuid()
self.texture_registry_tag = dpg.generate_uuid()
with dpg.texture_registry(show=False,
tag=self.texture_registry_tag):
dpg.add_raw_texture(width=self.img_w,
height=self.img_h,
default_value=np.zeros(
self.img_w*self.img_h*3),
format=dpg.mvFormat_Float_rgb,
tag=self.texture_tag)
dpg.add_image(self.texture_tag)
def __del__(self):
print('clear image')
dpg.delete_item(self.texture_tag)
print('texture deleted')
if __name__ == "__main__":
dpg.create_context()
dpg.create_viewport(title='example')
dpg.set_viewport_min_width(800)
dpg.set_viewport_min_height(600)
img_frame = ImageDraw()
dpg.setup_dearpygui()
dpg.show_viewport()
try:
dpg.start_dearpygui()
except Exception:
print(format_exc())
finally:
dpg.destroy_context() |
Beta Was this translation helpful? Give feedback.
You just need to "delete_item(...)". This will remove them from the texture registry. Once the last item using the texture is deleted, it will unload the texture completely.