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

Fix memory leak on macOS #2092

Merged
merged 3 commits into from
Oct 20, 2021

Conversation

xiaopengli89
Copy link
Contributor

Connections
#1783

Description
If we run the water example and open the Activity Monitor, and then do nothing (especially do not move the mouse to the water window), we will observe that the memory of the water process will keep growing. If we use the AMD discrete graphics card, it will grow by several megabytes per second. Using Intel integrated graphics is several hundred kilobytes per second. If we do some operations on the water window (such as moving the mouse), the memory will be reclaimed.

截屏2021-10-19 下午2 20 46

Using Instruments to monitor the memory allocation, confirmed that RenderCommandEncoder, BlitCommandEncoder and label will not be recycled without interaction.

Wrap new_render_command_encoder, new_blit_command_encoder and set_label into an AR pool can resolve the problem.

Testing
Run the water example in the same way and observe the memory changes.

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for identifying and fixing the issue!
Just a few notes before we proceed

wgpu-hal/src/metal/command.rs Outdated Show resolved Hide resolved
wgpu-hal/src/metal/command.rs Outdated Show resolved Hide resolved
wgpu-hal/src/metal/command.rs Show resolved Hide resolved
@kvark kvark merged commit a59a627 into gfx-rs:master Oct 20, 2021
@kvark kvark added the PR: needs back-porting PR with a fix that needs to land on crates label Oct 20, 2021
kvark pushed a commit to kvark/wgpu that referenced this pull request Oct 22, 2021
* Fix memory RenderCommandEncoder, BlitCommandEncoder, label leak on macOS

* Don't wrap autoreleasepool when blit command encoder is already active

* Revert wrap set_label, instead focus on gfx-rs/metal-rs#218
kvark pushed a commit that referenced this pull request Oct 22, 2021
* Fix memory RenderCommandEncoder, BlitCommandEncoder, label leak on macOS

* Don't wrap autoreleasepool when blit command encoder is already active

* Revert wrap set_label, instead focus on gfx-rs/metal-rs#218
@kvark
Copy link
Member

kvark commented Oct 22, 2021

Published in wgpu-hal-0.11.4

@kvark kvark removed the PR: needs back-porting PR with a fix that needs to land on crates label Oct 22, 2021
@xiaopengli89 xiaopengli89 mentioned this pull request Oct 7, 2022
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants