-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
Memory Leak #2677
Comments
What does the code do? Is this your solution? Or is this to demonstrate the memory leak? How does it show that there is a memory leak? |
—— can't be execute destructor function(like annotation). But if others or this one not contain the mapControl that can execute desctructor. so now i create mapControl on "OnAttachedToVisualTree" to reduce the problem. |
to simple test the problem like this:
wo can see the MapControl can't execute the destructor. maybe the control member reference some global variant to cause the problem. |
guess other : class MapControlEx : MapControl
{
public MapControlEx()
{
var tileLayer = Mapsui.Tiling.OpenStreetMap.CreateTileLayer();
Map?.Layers.Add(tileLayer);
}
~MapControlEx()
{
Trace.WriteLine(GetType().FullName);
}
}
class ControlEx : ContentControl
{
~ControlEx()
{
Trace.WriteLine(GetType().FullName);
}
} can't execute the "~MapControlEx()" too. |
I created a memory leak test like we had for Xamarin.Forms and it is green #2678. I have to investigate your kind of testing next. |
I looked into this a bit more. Not completely sure what exactly the problem is your struggling with. My guess is that you do not see an increase in memory use but you want to the finalizer to be called. The MapControl implements IDispose however and you should call Dispose() on it. In the MapControl.Dispose method we call Also I wonder if it is a good idea to inherit from the MapControl. Nowadays I am more inclined to make classes sealed because it is hard to correctly design for inheritance, and it is hard to implement a derived class because you have to guess how the parent class works. |
Pay attention to the test in the last screenshot. The use of inheritance here is only to simplify the proof that it has not been released by GC. During the usage process (starting from the constructor), I aimed to detect the release of static and dynamic resource management, and then discovered that the view tree could not be cleaned up. Then we investigated various controls and found that there was an issue with locating the map control. As it is an editor (with a history it maybe reuse), it has to be written to the "AttachViusalTree" event and set to null during “DettachVisualTree” so that the parent control can be released and the impact range can be reduced. I will continue to observe the impact of this issue in the future. Thank you for your reply. |
If you can provide a minimal reproducible sample I will further investigate this. |
|
avalonia 11.0.6
mapsui 4.1.2
windows 11
if write by control's member that can't be execute destructor function(like annotation). now i use "attach" to reduce the problem.
The text was updated successfully, but these errors were encountered: