- Home /
What is SendMouseEvents and why is it allocating memory every frame?
Hi there, I've been doing some profiling recently and in the profiler I see that SendMouseEvents.DoSendMouseEvents() is always present and allocates 76 bytes (if the mouse is not over the game window) or around 1.8K when it is. Is this a real method or is it something to do with profiling the app? I am profiling in the editor ATM.
I ask because I have been following the advice of doing a GC.Collect() every 30 frames, but contrary to the advice this is profiling as taking around 12MS (and not 5MS) and that's on the desktop, the amount of memory allocated in this time is small < 60K. Is this collection inflated in the profiler?
Thanks Bovine
Incidentally the GC.Collect() can only occur every frame if your heap size is small, $$anonymous$$e was more like 3$$anonymous$$B and this takes a long time to collect, especially on mobile. We've taken Unity's advice and:
GC.Collect() when we can - opening player's inventory; loading a level
Artificially allocate on the heap to cause the heap to grow and then free that up. This gives us 3$$anonymous$$B of headroom, so a a collect only happens by itself every 10-20 $$anonymous$$utes. The player will find some item and enter the inventory in this time typically I would imagine.
We're still trying to find out what is allocating, but I've not profiled for memory leaks lately...
Any news on this? I'm also seeing this in my project. It's the only thing allocating any memory while the game is running, so I'd really like to get rid of it.
I chatted to someone at Unite about this - practical upshot is that it's some internal Unity thing.
Also should point out that in Unity 3 there are significant differences and inaccuracies between deep profile and ordinary profile mode when viewing memory allocations.
Answer by Stardog · Jul 26, 2018 at 03:54 AM
It seems to be an editor-only problem. It should not occur in a build.
https://forum.unity.com/threads/sendmouseevents-gc-collect-spike-issue.506963/#post-3306951
Your answer
Follow this Question
Related Questions
Profiler spikes 1 Answer
Total memory allocated increases indefinately from .80GB untill crash 3 Answers
Performance going down over time 2 Answers
ManagedHeap.ReservedUnusedSize 0 Answers
Online, Possible Memory Leaks with RPC 0 Answers