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

Viewport3DX has memory leaks #2060

Open
SuperYF-86 opened this issue Dec 1, 2023 · 5 comments
Open

Viewport3DX has memory leaks #2060

SuperYF-86 opened this issue Dec 1, 2023 · 5 comments

Comments

@SuperYF-86
Copy link

Multiple Viewport3DXs sharing a single EffectsManager can improve loading speed, but it can also lead to memory leaks. I'm not sure if this is a bug or if I haven't found the right way to dispose the Viewport3DX?

%C6Y9K7)X91WBZU_ N413IV

Some resources never seem to get cleaned up when sharing EffectsManager.
NPW1KAF7UZP{U1YVDOKU8
2R VGB89%MR@OYFHR46S58S

This is the demo project:
ViewportMemoryLeakTest.zip

@holance
Copy link
Member

holance commented Dec 2, 2023

Yes, there are some internal caches for things like shaders etc. So as long as the memory is not keeping increment each time you load an new scene, it should be ok.

@SuperYF-86
Copy link
Author

Yes, there are some internal caches for things like shaders etc. So as long as the memory is not keeping increment each time you load an new scene, it should be ok.

I add a PointNode for each Viewport3DX.

cd

<hx:Element3DPresenter Content="{Binding Root }" />

pts_sc

It is indeed not possible to release resources correctly when Viewport3DX shares the EffectsManager.

fine

leak1

leak2

demo:
ViewportMemoryLeakTest.zip

@holance
Copy link
Member

holance commented Dec 5, 2023

I don't see there is any memory leaks. For your tests, you didn't dispose the effects manager after closing all the windows. Like I said, effects manager creates a set of cache automatically to improve performance. It is not memory leak.

Here is the memory usage for the shared effects manager:
image
You can see every time you create and close all windows, memory went back to the same level. Of course, it won't be back to the level at the beginning because of the caching. You can dispose the effects manager if you really need to release all resources.

@SuperYF-86
Copy link
Author

I don't see there is any memory leaks. For your tests, you didn't dispose the effects manager after closing all the windows. Like I said, effects manager creates a set of cache automatically to improve performance. It is not memory leak.

Here is the memory usage for the shared effects manager: image You can see every time you create and close all windows, memory went back to the same level. Of course, it won't be back to the level at the beginning because of the caching. You can dispose the effects manager if you really need to release all resources.

You're right, it shouldn't be a memory leak. Because memory usage doesn't increase indefinitely.

Viewport3DX seems to follow some kind of lazy pattern. It doesn't actively update unless the rendering interface has changed.

I have observed that when a Viewport3DX Camera has changed, some resources are being freed up quickly.

res_01

I guess when I need to actively release resources, I need to make sure that at least one active Viewport3DX exists in the current project, or create a new one. Trigger its internal resource release mechanism by updating its rendering state.

I don't know if this approach is officially recommended, but at least it works for my project.

Anyway thanks for your reply, it helps me a lot.

@holance
Copy link
Member

holance commented Dec 6, 2023

You need to force gc multiple times to release resources, there's nothing to do with viewport.

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

No branches or pull requests

2 participants