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

HelixToolkit.UWP.Viewport3DX has memory leaks #1185

Closed
fmExcense opened this issue Jun 24, 2019 · 9 comments
Closed

HelixToolkit.UWP.Viewport3DX has memory leaks #1185

fmExcense opened this issue Jun 24, 2019 · 9 comments

Comments

@fmExcense
Copy link

Hi,

In my app, i'm a using a UserControl which includes a Viewport3DX. This UserControl is attached to the xaml tree and detached from the xaml tree when the user opens it or close it. I'm using a single EffectManager which is shared by all the Viewport3DX instances.

I suspect the Viewport3DX control does not correctly free all its resources when it is detached. For example, binding to Items.CollectionChanged is never unbound when the view is detached. The properties for which a callback are registered are not unregistered. I am using Assimp to import my models. Some MemoryStreams (TextureModel) used by the Viewport3DX (ViewCubeMaterialCore, BillboardText3D) are not disposed once the view is detached.

Can you have a look? Thanks!

@holance
Copy link
Member

holance commented Jul 13, 2019

Could you upload a simple demo for this issue?

@holance
Copy link
Member

holance commented Aug 25, 2019

Are you creating new viewport frequently? After you detach it from the visual tree, you need to manually set its EffectsManager to null (If using binding, set its DataContext to null). Otherwise resources will not be released.

@fmExcense
Copy link
Author

Hi holance,

Sorry for the late reply... I tried your suggestion above, but it does not seem to release properly all the resources used by the viewport3DX.

I've made a sample app, which purpose is just to attach and detach a Viewport3DX object. The Viewport3DX detached is never collected by the garbage collector (collector can be called using CTRL+G keys).
All the viewport3DX objects created share the same EffectManager, Geometry3D & Materials objects. So, no new textures are created when creating a new Viewport3DX.
But if you inspect the memory heap, new TextureInfo are created each time a Viewport3DX object is created. MemoryStreams attached to these TextureInfo are not disposed when detaching the Viewport3DX from the scene.

I guess i'm not doing things correctly when detaching the Viewport3DX object... Maybe you can have a quick look at the sample app?

Thanks a lot,
HelixLeaks.zip

@holance
Copy link
Member

holance commented Sep 14, 2021

Let me know if you are still getting leaks.

@fmExcense
Copy link
Author

Hi holance,

Thanks for your reply! I've tried my sample app with the develop branch of the helix toolkit repo, where your patch has been merged. When I attach / dettach a viewport3DX, the object is not collected by the garbage collector (see the screenshot belown, 3 viewport3DX were created, none of them was removed by the GC

image

I do the following to remove my Viewport3DX object:

view3D.Detach(); view3D.Items.Remove(model3d); view3D.Items.Remove(light); view3D.DataContext = null; view3dContainer.Children.RemoveAt(0);

Am i missing something here?

The EffectsManager is not disposed when removing a Viewport3DX. All Viewport3DX objects created share the same EffectManager. The EffectManager is disposed when the user navigates to another Page.

Thanks for your help!

@holance
Copy link
Member

holance commented Sep 16, 2021

I am using following:

                view3D.EffectsManager = null;
                view3D.Items.Clear();
                view3D.DataContext = null;
                view3dContainer.Children.Clear();
                view3D.Dispose();
                view3D = null;
                light = null;
                model3d.Dispose();
                model3d = null;
                GC.Collect(2, GCCollectionMode.Forced);
                GC.Collect(2, GCCollectionMode.Forced);
                GC.WaitForFullGCComplete();

@fmExcense
Copy link
Author

Hi holance,

Using your code, it works 👍

Do you plan to include your fix to a 2.18.1 version?

Thanks!

@fmExcense
Copy link
Author

Hi holance,

Any chance that you provide a new release with the hotfix for the Viewport3DX leaks soon?

Thanks,

@holance
Copy link
Member

holance commented Sep 24, 2021

Probably early October.

@holance holance closed this as completed Sep 24, 2021
holance added a commit that referenced this issue Nov 4, 2021
Add missing configuration to ItemsModel3D re-loading (ref #1185, #1643)
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