jeffreylanters / react-unity-webgl

React Unity WebGL provides a modern solution for embedding Unity WebGL builds in your React Application while providing advanced APIs for two way communication and interaction between Unity and React.
https://react-unity-webgl.dev
Apache License 2.0
1.7k stars 160 forks source link

memory leak with multipaging, unload doesn't work #557

Closed rn-lazuka closed 1 month ago

rn-lazuka commented 1 month ago

Please avoid duplicates

Language and Compiler

Babel and WebPack JavaScript

What environment are you using?

Static File Serving

When does your problem occur?

When the Unity Component unmounts

What does your problem relate to?

The problem seems Module related

React-Unity-WebGL Version

9.5.2

React Version

18.2.0

Unity Version

2022.3.19f1

What happened?

https://github.com/jeffreylanters/react-unity-webgl/assets/58468458/cb51b3ec-690a-4525-ac0e-b9faee06ca1b https://github.com/jeffreylanters/react-unity-webgl/assets/58468458/d63f37e1-0b22-42a1-984d-623ce6a4fc98 I have a multi-page React application, and I created a page specifically for launching all the games I have. The problem is that when I open any game, Unity gets allocated in memory. When I navigate to another page and then open the same game or any other game, a new memory slot gets allocated each time, eventually leading to lags or Unity crashing due to memory issues. I tried using the unload method, and while the logs indicate it's working, I don't see any actual memory being freed. I've resorted to reloading the page to free up memory, but is there another solution?

Reproducible test case

Just create multipage app and try to open game few times

Would you be interested in contributing a fix?

jeffreylanters commented 1 month ago

Looks like a duplicate of #22