Closed ryjacky closed 6 months ago
Thank you for providing detailed information and code snippets.
I tested the provided code in both a Dart-only project and a Flutter app, and I can confirm your observation about the memory usage going up when the mouse is moving. Interestingly, I also observed this behavior in a Dart-only project, both when running it with dart run --observe example.dart
and after compiling to an executable with dart compile exe example.dart
.
After poking around with DevTools, I saw that a significant number of MouseHookStruct
and POINT
struct instances have been created. This is not surprising, since the contents of these structs are accessed from the following line:
_sendPort.send(MouseMoveEvent(pMouseStruct.ref.pt.x, pMouseStruct.ref.pt.y));
I also noticed that when the number of struct instances reached significant levels (thousands, even tens of thousands), the Dart GC stepped in like a hero, and memory usage dropped significantly.
Based on my analysis, there is no clear evidence of a memory leak here. If you have any doubts, I recommend you consider filing an issue to the Dart SDK repository for further investigation.
I'm writing a mouse hook with the following code (at the end) and it causes a memory leak at the message loop:
To reproduce, just copy the following code into a flutter project and call MouseHook.isolated(), this will create a new isolate that runs the message loop. Keep moving the mouse and the memory usage will rise as long as the mouse is moving.
The following is what I've tried:
Could anyone help to check if there is a problem with my code or is it a bug in the win32 package?
The same C++ code