Memory Allocation Issue with Tween.Custom Method #74
-
Hey everyone,
Despite SomeMethod being an empty method and using the free allocation way of calling the tween, it seems that memory is still being allocated. I've attached a screenshot showcasing the memory allocation associated with this code. One thing to note is that the allocation only happenes the first time the above Tween.Custom is called. After that every time its called it will not allocate any memory. Those benchmarks are done on a standalone build outside the Unity editor. Now the real story is that I've wrote the code above just to see whats going wrong with my original code which is this:
I'm calling this tween 3 times in my code (with a little variation in each call) without knowing that it allocates 5KB of memory every time I call it. I've tried changing the above code and the results still the same:
I'm unsure why memory is being allocated in this scenario and how I can optimize it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey Kinan, thanks for a great thread! The GC Alloc topic is complicated, and I should write a detailed article on GC memory allocations in PrimeTween. Let me break down your question into multiple answers:
|
Beta Was this translation helpful? Give feedback.
-
Most likely, you're experiencing the frame drop because you're running the game with Profiler. Profiler greatly influences the actual game performance, especially in the Deep Profile mode. PrimeTween's delegate allocation is extremely small and it should not be noticeable in production builds, so there is no need to cache or pre-warm anything. |
Beta Was this translation helpful? Give feedback.
Hey Kinan, thanks for a great thread!
The GC Alloc topic is complicated, and I should write a detailed article on GC memory allocations in PrimeTween. Let me break down your question into multiple answers:
Mono.JIT entries come from the Mono's Just-In-Time compilation. These allocations are inevitable and happen with the Mono backend every time any line of C# code runs the first time. There is no way to prevent them because this is how Mono works. If you want to run any code, Mono should first compile it before running, and this shows in the Profiler. IL2CPP builds doesn't have this.
To validate this, make an IL2CPP build, attach the Profiler to it, and observe that there are no more Mo…