Out of memory WebGL random

Hi
In our application build with Unity 2021.3.20f1 for WebGL, on Chrome and Firefox, we get sometimes ‘out of memory’ error.
Can anybody say something that could be a reason?
It happens on the scene where are:
-video player rendering to RenderTexture on Sphere
-VideoKit from NatML (and I need permission for using a camera and microphone)
-small amount of UI

This is a log from browser:

exception thrown: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds
    at MemoryProfiler::UnregisterAllocation(void*, unsigned long, MemLabelId const&) (https://myapplication.net/Build/Build0011.wasm:wasm-function[133919]:0x292a35d)
    at MemoryManager::smile:eallocate(void*, MemLabelId const&, char const*, int) (https://myapplication.net/Build/Build0011.wasm:wasm-function[134055]:0x2937ffa)
    at free_alloc_internal(void*, MemLabelId const&, char const*, int) (https://myapplication.net/Build/Build0011.wasm:wasm-function[134070]:0x2939b9b)
    at dynamic_array<DynamicVBOBuffer, 0ul>::~dynamic_array() (https://myapplication.net/Build/Build0011.wasm:wasm-function[129479]:0x275bbfc)
    at SharedMeshData::~SharedMeshData() (https://myapplication.net/Build/Build0011.wasm:wasm-function[129529]:0x275f9c9)
    at Mesh::ReleaseAndAssignMeshData(SharedMeshData*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[130418]:0x27d1c1a)
    at Mesh::~Mesh() (https://myapplication.net/Build/Build0011.wasm:wasm-function[130474]:0x27e2959)
    at DestroySingleObject(Object*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[133715]:0x291d81b)
    at DestroyObjectHighLevel_Internal(Object*, bool) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131309]:0x2852ce0)
    at DestroyObjectHighLevel(Object*, bool) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131310]:0x2852d05)
    at Object_CUSTOM_DestroyImmediate(Il2CppObject*, unsigned char) (https://myapplication.net/Build/Build0011.wasm:wasm-function[132494]:0x28baf45)
    at Object_DestroyImmediate_m737E5829FEEAE70EE7A004D172042D52E336E1E3 (https://myapplication.net/Build/Build0011.wasm:wasm-function[86880]:0x1807c69)
    at Object_DestroyImmediate_m6336EBC83591A5DB64EC70C92132824C6E258705 (https://myapplication.net/Build/Build0011.wasm:wasm-function[86881]:0x1807c9f)
    at TextMeshProUGUI_OnDestroy_mF6F5098912944CBAEE8F9162CBC8513B6FCB4DCB (https://myapplication.net/Build/Build0011.wasm:wasm-function[17478]:0x4ae1a3)
    at RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915(void (*)(), MethodInfo const*, void*, void**, void*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[107106]:0x1b94576)
    at il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**) (https://myapplication.net/Build/Build0011.wasm:wasm-function[109186]:0x1bbc334)
    at dynCall_iiii (https://myapplication.net/Build/Build0011.wasm:wasm-function[134422]:0x29528cf)
    at https://myapplication.net/Build/Build0011.framework.js:1142:20
    at invoke_iiii (https://myapplication.net/Build/Build0011.framework.js:22666:10)
    at il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) (https://myapplication.net/Build/Build0011.wasm:wasm-function[109160]:0x1bbb7f2)
    at il2cpp_runtime_invoke (https://myapplication.net/Build/Build0011.wasm:wasm-function[109230]:0x1bbde65)
    at scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) (https://myapplication.net/Build/Build0011.wasm:wasm-function[133519]:0x2907910)
    at ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131494]:0x2871db6)
    at ScriptingInvocation::InvokeChecked(ScriptingExceptionPtr*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131499]:0x2871fb5)
    at SerializableManagedRef::CallMethod(Object&, ScriptingMethodPtr) (https://myapplication.net/Build/Build0011.wasm:wasm-function[111831]:0x1c42a86)
    at MonoBehaviour::WillDestroyComponent() (https://myapplication.net/Build/Build0011.wasm:wasm-function[131431]:0x286c706)
    at PreDestroyRecursive(GameObject&, unsigned long*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131306]:0x2851912)
    at PreDestroyRecursive(GameObject&, unsigned long*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131306]:0x28519d1)
    at PreDestroyRecursive(GameObject&, unsigned long*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131306]:0x28519d1)
    at PreDestroyRecursive(GameObject&, unsigned long*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131306]:0x28519d1)
    at PreDestroyRecursive(GameObject&, unsigned long*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131306]:0x28519d1)
    at PreDestroyRecursive(GameObject&, unsigned long*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131306]:0x28519d1)
    at PreDestroyRecursive(GameObject&, unsigned long*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131306]:0x28519d1)
    at DestroyObjectHighLevel_Internal(Object*, bool) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131309]:0x28528ff)
    at DestroyObjectHighLevel(Object*, bool) (https://myapplication.net/Build/Build0011.wasm:wasm-function[131310]:0x2852d05)
    at RuntimeSceneManager::UnloadSceneInternal(UnityScene*, UnloadSceneOptions) (https://myapplication.net/Build/Build0011.wasm:wasm-function[112011]:0x1c5519d)
    at UnloadSceneOperation::IntegrateMainThread() (https://myapplication.net/Build/Build0011.wasm:wasm-function[111940]:0x1c4e1b2)
    at PreloadManager::UpdatePreloadingSingleStep(PreloadManager::UpdatePreloadingFlags, int) (https://myapplication.net/Build/Build0011.wasm:wasm-function[111933]:0x1c4d10b)
    at PreloadManager::UpdatePreloading() (https://myapplication.net/Build/Build0011.wasm:wasm-function[111935]:0x1c4d3ff)
    at InitPlayerLoopCallbacks()::EarlyUpdateUpdatePreloadingRegistrator::Forward() (https://myapplication.net/Build/Build0011.wasm:wasm-function[131152]:0x284140c)
    at ExecutePlayerLoop(NativePlayerLoopSystem*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[111874]:0x1c46e96)
    at ExecutePlayerLoop(NativePlayerLoopSystem*) (https://myapplication.net/Build/Build0011.wasm:wasm-function[111874]:0x1c46f32)
    at MainLoop() (https://myapplication.net/Build/Build0011.wasm:wasm-function[129004]:0x27020c2)
    at dynCall_v (https://myapplication.net/Build/Build0011.wasm:wasm-function[134425]:0x29528ef)
    at https://myapplication.net/Build/Build0011.framework.js:1142:20
    at browserIterationFunc (https://myapplication.net/Build/Build0011.framework.js:15075:13)
    at callUserCallback (https://myapplication.net/Build/Build0011.framework.js:13254:3)
    at Object.runIter (https://myapplication.net/Build/Build0011.framework.js:13315:4)
    at Browser_mainLoop_runner (https://myapplication.net/Build/Build0011.framework.js:13229:20)

Try profiling, specifically using the memory profiler package. This isn’t a case where anyone would say “Of course, it’s obvious, just do XXX”. :wink:

Check and experiment with the WebGL player settings related to memory. For example the usual 20% memory size increase may not be suitable for your case, or you may see better stability if you increase the initially allocated memory thus reducing the need to allocate more memory on the fly which depends on having enough contiguous free memory available.

But first profile to see if you have any memory leaks. To make this easier, closely observe memory usage in editor playmode since leaks or short but high usage spikes may already be visible in the editor.