You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not clear to me whether canvas geometry needs to be explicitly disposed of and what is cleaned up on dispose. I have a viewmodel which is responsible for creating CanvasGeometry and maintains a list of geometry to draw. This is an internal app so I am not concerned with the device changing, basically when the canvas is loaded a reference is set on the viewmodel so that I can access the device and create geometry/perform geometric operations in my viewmodel which is triggered by user actions results in a list of items to draw on the canvas. The viewmodel is then responsible for invalidating the canvas to trigger a redraw.
I have added the recommend unload behaviour to remove the canvas from the visual tree and set the Canvas to null to ensure this is garbage collected. Is this enough to ensure that any unmanaged resources are cleaned up?
The text was updated successfully, but these errors were encountered:
That should be enough! As long as you aren't holding a reference to the CanvasGeometry, it will get garbage collected. When this happens, Win2D will release its underlying unmanaged Direct2D objects. You shouldn't need to explicitly call Dispose. Disposing this object just releases its references to the CanvasDevice or factory (which also happens when the object is garbage collected).
I just did an empirical test where I created millions of CanvasGeometries in a loop, and it didn't increase the app's memory size.
@getrou well I do hold a reference to the CanvasGeometry whilst the page is active, then when the user navigates away any CanvasGeometry will be garbage collected, along with correctly disposing of the Canvas. I expect this is fine as the CanvasGeometry won't outlive the Canvas.
But why then does it implement IDisposable if it releases its references when garbage collected? In what context would I need to ensure I call Dispose?
FYI This came about because I increased my analyzer warnings resulting in many errors for all my Win2D code.
It's not clear to me whether canvas geometry needs to be explicitly disposed of and what is cleaned up on dispose. I have a viewmodel which is responsible for creating CanvasGeometry and maintains a list of geometry to draw. This is an internal app so I am not concerned with the device changing, basically when the canvas is loaded a reference is set on the viewmodel so that I can access the device and create geometry/perform geometric operations in my viewmodel which is triggered by user actions results in a list of items to draw on the canvas. The viewmodel is then responsible for invalidating the canvas to trigger a redraw.
I have added the recommend unload behaviour to remove the canvas from the visual tree and set the Canvas to null to ensure this is garbage collected. Is this enough to ensure that any unmanaged resources are cleaned up?
The text was updated successfully, but these errors were encountered: