Potential memory leak in MultiPolyLineVisual3D
PositionsList is a typical WPF's DepancedyProperty and has its OnChange handler. But if you reset its value to the already assigned value, then the OnChange handler is not called.

So, if you would call:
_multiPolyLineVisual3D.PositionsList = s.PointsCollection;

and then again (I assume s.PointsCollection is the same object instance):
_multiPolyLineVisual3D.PositionsList = s.PointsCollection;

The _multiPolyLineVisual3D would not get any notification about the change.

Therefore the PositionsList needs to be changed "for real" to notify the MultiPolyLineVisual3D about the change. Currently, the best way to do this is to set it to null and then back to the previous value (do not create a new List<Point3DCollection> - this is just a useless waste of objects that gets to GC). But I am planning to work on improving that in the future.

I assume that you are testing those two lines of code in a loop that runs in a test environment and that the lines are newer shown in the UI.

Each changed line is registered by Ab3d.Utilities.LinesUpdater class that handles rendering and updating the 3D lines. After each change of PositionsList, a new version of the line is added to the internal collection of LinesUpdater (you can get the number of registered lines with checking the Ab3d.Utilities.LinesUpdater.Instance.RegisteredLinesCount property). When the 3D line is actually shown, then the LinesUpdater can clean its collection and remove the unused registered lines. If you change PositionsList many times without showing the lines, then you will see a lot of positions in the .Net heap. But once the line is shown, or when the _multiPolyLineVisual3D is collected by GC, then the internal collections will be also cleared (if no line is ever shown, you may need to call Ab3d.Utilities.LinesUpdater.Instance.Refresh method to force refreshing the list of lines - do this after _multiPolyLineVisual3D is collected by GC).

I have many tests to check this functionality. After your post, I have run them again and checked your use case in more details and as far I can see, the code is working properly. But maybe I am missing something.

LinesUpdater is crucial when the 3D lines are rendered with WPF 3D. But when Ab3d.DXEngine is used to render the 3D lines, then the LinesUpdater still collects the registered 3D lines, but once they are rendered by Ab3d.DXEngine, the lines are removed from the internal LinesUpdater collection.

Please try to simulate the 3D lines rendering in a real-world use case as much as possible. If some problems are found there, please provide more details so that I will be able to reproduce the problems.
Andrej Benedik

Messages In This Thread
RE: Potential memory leak in MultiPolyLineVisual3D - by abenedik - 01-22-2018, 01:10 PM

Forum Jump:

Users browsing this thread:
1 Guest(s)