hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.62k stars 669 forks source link

Memory increasing and crash if register raw texture and minimize window #2049

Open zlt999 opened 1 year ago

zlt999 commented 1 year ago

Version of Dear PyGui

Version: 1.8.0 Operating System: Windows 11

My Issue/Question

Occupied memory keep increasing and app finally crash, if register raw texture and minimize the app window (I'm running code from example: https://dearpygui.readthedocs.io/en/latest/documentation/textures.html#raw-textures)

To Reproduce

Steps to reproduce the behavior:

  1. Run the example code (https://dearpygui.readthedocs.io/en/latest/documentation/textures.html#raw-textures)
  2. Minimize the app window
  3. Wait and check occupied memory

Expected behavior

Hope memory not increasing when using raw texture and minimize the window

Screenshots/Video

Standalone, minimal, complete and verifiable example

# Here's code copied from example
import dearpygui.dearpygui as dpg
import array

dpg.create_context()

texture_data = []
for i in range(0, 100 * 100):
    texture_data.append(255 / 255)
    texture_data.append(0)
    texture_data.append(255 / 255)
    texture_data.append(255 / 255)

raw_data = array.array('f', texture_data)

with dpg.texture_registry(show=True):
    dpg.add_raw_texture(width=100, height=100, default_value=raw_data, format=dpg.mvFormat_Float_rgba, tag="texture_tag")

def update_dynamic_texture(sender, app_data, user_data):
    new_color = dpg.get_value(sender)
    new_color[0] = new_color[0] / 255
    new_color[1] = new_color[1] / 255
    new_color[2] = new_color[2] / 255
    new_color[3] = new_color[3] / 255

    for i in range(0, 100 * 100 * 4):
        raw_data[i] = new_color[i % 4]

with dpg.window(label="Tutorial"):
    dpg.add_image("texture_tag")
    dpg.add_color_picker((255, 0, 255, 255), label="Texture",
                         no_side_preview=True, alpha_bar=True, width=200,
                         callback=update_dynamic_texture)

dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
hoffstadt commented 1 year ago

The code sample you provided does not show increasing memory usage on my machine. I'm testing with windows 10. I will have to check a windows 11 machine.

zlt999 commented 1 year ago

Ah by the way, I'm using python version 3.10.7

zlt999 commented 1 year ago

Just found memory also increasing when I lock PC

kuchi commented 9 months ago

I have observed the same issue on windows 11.

OS: Windows 11 Dearpygui version 1.10 Python 3.11

If you minimize the app the memory for the raw texture seems to not get de-allocated each time a frame update is happening. The memory linearly increases proportionally to the size of the raw texture image. It will increase until the app hangs and crashes. Although no error message is printed in the terminal. If you de-minimize the window then it stops increasing in memory usage but it still does not free the memory that was not deallocated while minimized.

If you increase the size of the raw texture, the effect linearly increases. So it does appear to be a direct issue with the raw texture and windows 11. This did not seem to be an issue on Windows 10, although now all my systems were recently upgraded to 11 so I don't have access to Windows 10 anymore to test. But I only started to get bug reports from users of our apps when they upgraded to 11.

kuchi commented 9 months ago

I was able to log into a Windows 10 machine and verified that the issue is isolated to Windows 11.

OS Windows 10 Dearpygui version 1.10 Python 3.11

No issue - only seen on Windows 11.

hoffstadt commented 2 months ago

I have Windows 11 running with the sample code minimized and I'm not seeing any leaks:

image

I'm running Python 3.9, 3.10, and 3.11. I'm using an AMD GPU. What GPU are you guys using?

kuchi commented 2 months ago

I just ran the code and if I minimize the window and then look in the task manager, the python process memory continues to linearly increase until the app uses all available memory and crashes. If I don't minimize the window it does not do this, the memory usage stays constant.

The system I just tested it on is a HP ZBook Firefly G8 which has a NVIDIA T500 (4 GB GDDR5 dedicated) graphics card and Intel Iris Xe Graphics.

I am running python 3.11.

hoffstadt commented 2 months ago

What timeframe? I let it run for about 10 mins.

kuchi commented 2 months ago

It starts happening immediately. I can see the memory usage start to increase right after minimizing. On Apr 15, 2024, at 4:17 PM, Jonathan Hoffstadt @.***> wrote: What timeframe? I let it run for about 10 mins.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

zlt999 commented 2 months ago

Here's the environment I'm using