Introduced by Backtrace
Relating to monitoring Unity recreation builds for doable reminiscence points, the Unity reminiscence profiler module is a crucial software. Whereas the built-in Reminiscence Profiler beneath the Profiler window provides you primary details about the reminiscence, the extra downloadable Reminiscence Profiler package deal can be utilized to investigate your recreation’s reminiscence utilization intimately. When mixed with Backtrace’s potential to detect out-of-memory points on cell platforms, you possibly can effectively discover and repair issues earlier than they smash recreation efficiency and impression recreation expertise.
Unity Reminiscence Profiler Module
The Unity Reminiscence Profiler Module will be put in in any Unity Venture to detect and resolve reminiscence leaks, cut back ANRs, hangs and crashes and optimize recreation loading instances. When mixed with Backtrace, you cannot solely enhance efficiency on slower gadgets but additionally goal these gadgets that have been beforehand out of attain as a consequence of greater reminiscence necessities, thereby resulting in elevated gross sales and improved buyer retention.
Reminiscence Snapshot
One of the helpful options of the Reminiscence Profiler is the flexibility to take snapshots of various cut-off dates through the gameplay. The reminiscence profiler allows you to retailer and examine snapshots to examine for potential sources of reminiscence leaks by utilizing a ‘diff’-like software.
When two snapshots are in contrast, you possibly can probably discover points that beforehand went undetected. As an illustration, if there are extra new objects detected within the second scene than the primary, then that might level to a reminiscence leak. Moreover, you possibly can examine each snapshots to see if the second snapshot consumes much more reminiscence than the primary one and take motion as acceptable to repair the leak.
Tree Map
One other helpful characteristic of the Reminiscence Profiler Module is the Tree Map. It means that you can visualize which of the belongings used within the scene consumes probably the most reminiscence. Subsequently, the Tree Map can be utilized to shortly examine and optimize the reminiscence footprint of your recreation. In case you see that there’s a particular asset resembling a texture taking on a bit of your reminiscence, then it may be investigated additional. On cell gadgets, one widespread oversight is to neglect compressing an imported uncompressed texture.
Reminiscence Fragmentation
Relying upon the construct sort and the complexity of a recreation, fragmentation of reminiscence can finally result in an utility operating out of reminiscence (OOM). Even when an utility doesn’t run out of reminiscence, it could possibly trigger pointless frequent invocations of Rubbish collector and/or enlargement of heap, which can result in a degradation in recreation efficiency. The reminiscence fragmentation software allows you to examine how the reminiscence is allotted and to what extent it’s being fragmented. You should use this info to additional optimize your recreation by restructuring code that reduces reminiscence fragmentation. For instance, reusing collections and arrays as a substitute of making new collections can cut back reminiscence fragmentation.
Frequent points that result in reminiscence leaks
There are a number of methods during which reminiscence leaks might happen however the next are the most typical:
Use of Persistent GameObjects
One of the widespread oversights that result in reminiscence leaks is an improper use of persistent recreation objects. Usually, builders could use a Singleton class or mark a element as DontDestroyOnLoad. Whereas your recreation structure could require some lessons to persist throughout scenes, they might additionally result in reminiscence leaks. If the objects which might be referenced by the persistent lessons will not be unloaded, then these reminiscence leaks might shortly construct up and your recreation might threat operating out of reminiscence. One other state of affairs that might result in a reminiscence leak is when consumer allotted objects or assets will not be unloaded or cleaned up after unloading a Scene.
Spawning with out correct object administration
The commonest mistake newbie recreation builders could make is to make use of Instantiate an object however then neglect to destroy it. Over a interval, instantiating objects repeatedly might result in the sport operating out of reminiscence. Likewise, utilizing particle techniques that both generate too many particles or spawning particles in an Replace loop might result in efficiency degradation and threat operating out of reminiscence.
Professional Tip: It’s price noting that in case you are repeating the cycle of spawning and destroying recreation objects (or recreation objects containing particle results) very regularly, think about using an Object Pooling system to cut back the chance of Rubbish Collector (GC) being invoked regularly (because it might result in efficiency degradation).
Improper use of occasions
In a VR recreation real-time simulation recreation challenge supervised by the creator, the sport would progressively decelerate after a couple of in-game days elapse and in the end result in the sport getting hanged (Software Not Responding/ANR). Preliminary prognosis revealed that the applying was operating out of reminiscence. Nevertheless, conventional strategies of troubleshooting the sport failed because the code appeared to examine all the suitable packing containers resembling utilizing an object pooling system and optimizing textures and different loaded belongings. Thereafter, the creator urged that the reminiscence profiler be deployed to snapshot two situations of the in-game days to investigate the reminiscence utilization and to examine for the supply of the difficulty. It turned out that occasions have been being registered by two completely different scripts however just one script was unregistering the occasion, which retained objects within the reminiscence even after the scene was unloaded, thereby resulting in OOM.
Protecting reminiscence points in examine with Backtrace
Whereas there are a number of benefits of utilizing the downloadable Reminiscence Profiler Module to troubleshoot and stop reminiscence points through the growth stage, including Backtrace to your challenge additional protects your challenge by permitting you to establish points that beforehand went undetected throughout growth and playtest classes. Backtrace means that you can detect Software Not Responding (ANRs) and Out Of Reminiscence (OOM) exceptions on cell gadgets so you possibly can additional dig into reminiscence points by utilizing Backtrace in tandem with the Reminiscence Profiler to search out, troubleshoot and resolve memory-related points earlier than they get out of hand.
Keep tuned for the following weblog on how Backtrace will be configured to detect OOM exceptions on cell builds!
Take a look at the assets under to be taught extra about Reminiscence Profiler and the best way to set up it in your subsequent Unity Venture.
Attempt Backtrace right this moment to start out detecting errors, reminiscence points and ANRs earlier than they smash your buyer’s gaming expertise.
Backtrace is a Unity VSP (Verified Answer Accomplice). Be taught extra about how we work with Unity and sign up for free right this moment: