-
Notifications
You must be signed in to change notification settings - Fork 977
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
Fix memory leak on macOS #3056
Fix memory leak on macOS #3056
Conversation
From Apple's autoreleasepool doc:
I have also checked several official Metal demos, all Metal instructions put into @autoreleasepool is not necessary. Also, no resulting memory leaks were observed on Intel and M1 Macs. |
If the user does not interact with the program for a long time, leakage will occur, such as a video playback software on mac, but the user only operates remotely through the mobile phone, related #2092. |
Indeed, after the window is completely occluded, the occupied memory will suddenly increase to a higher level, and then it can be observed that it will slowly decrease, and then there will be repeats, but it will always be below that highest value. I also tested Apple's official metal demo and didn't observe this phenomenon. This phenomenon is not like a memory leak caused by the wgpu itself, but a combination of wgpu + winit, and my personal projects that do not use winit have not observed this problem. |
The problem with the occluded window should be related to this issue #1783. |
Thanks for the link, I didn't realize this issue has been discussed for so long. Basically I agree with the statement on this beby issue:
|
WebKit's metal-cpp doc mentions a way to debug autoreleasepool:
It doesn't seem to eliminate the missing autoreleasepool warning. And since autoreleasepool isn't zero-overhead, maybe we can dig a little deeper into the cause of the problem to make the metal backend perform better. |
I tested this pr with |
I'm quite unfamiliar with all this autorelease pool stuff, so I'll defer to general consensus if this is something we need. Less warnings sounds generally good though. |
2¢ from someone who once wrote a lot of Objective-C: If adding an autorelease pool reduces leaks, then there definitely should be an autorelease pool added. There might be a more ideal scope for the pool — wider to catch more things, or narrower to reduce the maximum accumulation of not-yet-autoreleased objects — but there should definitely be a pool. The only way adding an autorelease pool can cause harm (besides the cost of constructing it) is if code tries to Skimming, I don't see any risks of that in this PR, because the pools all end at the same time the function scope ends (and if the WGPU objects being returned were containing non- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool then, lets land this!
FWIW, I just tested my application with wgpu from git |
Checklist
cargo clippy
.Description
Fix remaining leaks for metal backend.