-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 in master branch (automation related?) #8240
Comments
Possibly related to #7751 |
Pretty weird, I used dotMemory as well to fix previous memory leak, and I used latest master (well, couple of days old now). And there was only one memory leak with old sample code. @grokys I will take a look tomorrow, but if you know something about automation what might be a reason here, it can help. @robloo while I am on it, I can fix that one too. Thanks for reminding. |
if you mean my sample code, then the previous one (menu related) didn't have this button, I've discovered it accidentally, while trying to reproduce another leak |
I think the reason for this memory leak is that the method responsible for removing one, two or three weak references is simply not called: I'm talking about I was told by @maxkatz6 that @grokys may know where this method can/should be called. Pinged the second one, hopefully he will reply and help with fix. |
Hey @flexxxxer I just talked to @grokys and asked him if he has any idea. Unfortunately, this seems to be hard to debug as e.g. "dotmemory can't really help with COM leaks". So it may take quite a while for us to find the root cause and track this down. Thank you for your hands off on this :-) |
Thanks @timunie . To address the usage of |
I have idea how to fix that (where call |
This problem still happens with latest master (11.2.999-cibuild0047389-alpha), but only on macOS |
I am trying to understand the code, it would be great if anybody could go through this and help me understand it. Native Avalonia/native/Avalonia.Native/src/OSX/automation.mm Lines 56 to 60 in d5ca06f
It is saved into a field here: Avalonia/native/Avalonia.Native/src/OSX/automation.mm Lines 93 to 100 in d5ca06f
And Avalonia/native/Avalonia.Native/src/OSX/automation.mm Lines 63 to 91 in d5ca06f
Avalonia/native/Avalonia.Native/src/OSX/automation.mm Lines 476 to 482 in d5ca06f
static void* RootProvider_GetPeerFromPoint(void* @this, AvnPoint point)
{
IAvnAutomationPeer __target = (IAvnAutomationPeer)global::MicroCom.Runtime.MicroComRuntime.GetObjectFromCcw(new IntPtr(@this));
var __result = __target.RootProvider_GetPeerFromPoint(point);
return global::MicroCom.Runtime.MicroComRuntime.GetNativePointer(__result, true);
} Lastly, let's see public static void* GetNativePointer<T>(T obj, bool owned = false) where T : IUnknown
{
if (obj is IMicroComShadowContainer container)
{
container.Shadow ??= new MicroComShadow(container);
void* ptr = null;
var res = container.Shadow.GetOrCreateNativePointer(typeof(T), &ptr);
if (owned)
container.Shadow.AddRef((Ccw*)ptr);
return ptr;
}
throw new ArgumentException("Unable to get a native pointer for " + obj);
} So it creates |
https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Native/AvnAutomationPeer.cs is the managed part. So if that is cleaned up it should also clean up the native part. |
I always was suspicious of these IAvnString usages: You can clearly see that AvnString is created on C# side, but never disposed. For file picker code I had a hack like this, ensuring that all of these strings will be disposed: Avalonia/src/Avalonia.Native/SystemDialogs.cs Lines 131 to 148 in 27e40b8
Which are all disposed together after file picked:
As well as on ObjC side all strings (ideally) should be released as soon as possible. For example, right when they are converted to NSStrings:
|
But yes, whole AutomationPeer leaking is a bigger object/problem than some strings. |
This issue is also on windows. We are using this with UIAutomation and we have that here. There is any news about it ? |
Describe the bug
The latest master branch (tested 11.0.4 and 0.10.999-cibuild0020870-beta cea6bc2) has a memory leak, probably related to Automation code.
Note: this is a regression from the current stable 0.10.x version (which doesn't have automation related modules).
To Reproduce
The repro is very simple - just add a button, press it and the button will not be freed anymore.
leak2
Screenshots
dotMemory screenshot:
Desktop:
The text was updated successfully, but these errors were encountered: