Skip to content
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

Investigate memoryleaks #353

Closed
4 tasks
Tracked by #387
almarklein opened this issue Feb 28, 2023 · 1 comment · Fixed by #403
Closed
4 tasks
Tracked by #387

Investigate memoryleaks #353

almarklein opened this issue Feb 28, 2023 · 1 comment · Fixed by #403
Labels

Comments

@almarklein
Copy link
Member

almarklein commented Feb 28, 2023

In #306 we explored the memoryleak of Lavapipe, and found out that Device objects leak memory on Windows too. To be fair, in practice you'd likely only use one device per process, but there are use cases for using multiple devices. Let's also do some testing on other objects, and report/fix errors upstream.

The purpose of this issue is to track known leaks. We want wgpu-py to be a reliable system without leaks.

Status

  • Adapter
    • All systems: Memory does grow, albeit very slowly. Could be a small leak?
  • Device
    • LavaPipe with Vulkan: Leaks significantly.
    • Windows with Vulkan/D3D12: Leaks significantly. Crashes at the 64th iter!
    • MacOS with Metal: Does not seem to leak.
  • Buffer
  • Texture
  • ...

Code to track (updated):

import gc
import psutil

import wgpu.backends.rs
import wgpu


p = psutil.Process()


def print_mem_usage(i):
    megs = p.memory_info().rss / 1024**2
    print(f"memory usage (round: {i}): {megs:.3f} MB")


if __name__ == "__main__":
    print_mem_usage(0)
    for i in range(500):
        adapter = wgpu.request_adapter(canvas=None, power_preference="high-performance")
        device = adapter.request_device()
        device.destroy()
        del device
        wgpu.backends.rs.delayed_releaser.release_all_pending()
        gc.collect()
        print_mem_usage(i + 1)

    wgpu.print_report()
@almarklein
Copy link
Member Author

almarklein commented Nov 4, 2023

Closing this because we have #403. Following up in #405 and #406.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant