Hey, before 5.6 we were able to examine the current memory usage through this code: Code (JavaScript): setInterval(function() { if (typeof TOTAL_MEMORY !== 'undefined') { try { var totalMem = TOTAL_MEMORY/1024.0/1024.0; var usedMem = (TOTAL_STACK + (STATICTOP - STATIC_BASE) + (DYNAMICTOP - DYNAMIC_BASE))/1024.0/1024.0; console.log('Memory stats - used: ' + Math.ceil(usedMem) + 'M' + ' free: ' + Math.floor(totalMem - usedMem) + 'M'); } catch(e) {} } }, 5000); This doesn't work anymore in 5.6 Any advice to get the same functionality? And with 5.6 it seems like the memory footprint is generally bigger. Is this something to expect? Regards, Chen
Below is a code snippet from the following blog post: https://blogs.unity3d.com/2016/12/05/unity-webgl-memory-the-unity-heap/ Code (JavaScript): GetDynamicMemorySize: function() { if (typeof DYNAMICTOP !== 'undefined') { return DYNAMICTOP - DYNAMIC_BASE; } else { // Unity 5.6+ return HEAP32[DYNAMICTOP_PTR >> 2] - DYNAMIC_BASE; } }
It doesn't work in FF 57 nor Chrome 62.0.3202.75 portable Builded by unity 5.6.3p2 it don't find TOTAL_STACK nor TOTAL_MEMORY nor any other (tried to comment lines and change if condition) my full version in index.html Code (JavaScript): <script> setInterval(function() { console.log("tick"); if (typeof TOTAL_STACK !== 'undefined') { console.log("mem.." //+ "GetTotalMemorySize = " + GetTotalMemorySize() + "; " + "GetTotalStackSize = " + GetTotalStackSize() + "; " + "GetStaticMemorySize = " + GetStaticMemorySize() + "; " + "GetDynamicMemorySize = " + GetDynamicMemorySize() + "; " + "GetReservedMemorySize = " + GetReservedMemorySize() + "; " ); } }, 5000); function GetReservedMemorySize() { return GetTotalStackSize() + GetStaticMemorySize() + GetDynamicMemorySize(); } function GetTotalMemorySize() { return TOTAL_MEMORY; // WebGLMemorySize in bytes } function GetTotalStackSize() { return TOTAL_STACK; } function GetStaticMemorySize() { return STATICTOP - STATIC_BASE; } function GetDynamicMemorySize() { if (typeof DYNAMICTOP !== 'undefined') { return DYNAMICTOP - DYNAMIC_BASE; } else { // Unity 5.6+ return HEAP32[DYNAMICTOP_PTR >> 2] - DYNAMIC_BASE; } } </script>
This is not working for me either. I posted a related question that calls back to this one: https://forum.unity.com/threads/emscripten-generated-variables-and-constants-in-unity-5-6.509344/