Skip to content

Fix memory leak on macOS - #2092

Merged
kvark merged 3 commits into
gfx-rs:masterfrom
xiaopengli89:fix-macos-encoder-label-leak
Oct 20, 2021
Merged

kvark merged 3 commits into
gfx-rs:masterfrom
xiaopengli89:fix-macos-encoder-label-leak

Conversation

@xiaopengli89

Copy link
Copy Markdown
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.

@xiaopengli89
xiaopengli89 force-pushed the fix-macos-encoder-label-leak branch from 454d149 to 3a44e06 Compare October 19, 2021 08:02

@kvark kvark left a comment

Copy link
Copy Markdown
Member

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

Comment thread wgpu-hal/src/metal/command.rs Outdated
Comment thread wgpu-hal/src/metal/command.rs Outdated
Comment thread wgpu-hal/src/metal/command.rs
@xiaopengli89
xiaopengli89 requested a review from kvark October 20, 2021 11:02
@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

kvark commented Oct 22, 2021

Copy link
Copy Markdown
Member

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 done
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