Skip to content

Memory leak caused by non disposed scene, when using routes #449

Closed
@fakedob

Description

@fakedob

Describe the bug

In our project, we use a bit big bigger models and we test our app on mobile browsers. While observing the memory, it became clear that unmounting the TresCanvas, does not properly dispose the scene and some (maybe all) internal objects. So navigating in and out a few times on iOS device, cause the page to crash and reload, because it runs out of memory.

Screenshot 2023-11-19 at 20 15 16

Unfortunately, my understanding of three.js is not much, but I had similar issues in the past and it was related to the way the scene and objects, that were added to the scene, being not properly disposed. Its possible that some references to some internal TresJS objects are also the cause of the issue. I just dont know.

Its also possible that I am missing something in the way I use the framework (which will be the best for me), so hopefully someone can give me a hand with this.

Thank you!

Reproduction

https://stackblitz.com/edit/tresjs-basic-tmk778

Steps to reproduce

To reproduce, open the reproduction link in a Chromium browser and use the Memory tab in the dev tools.
At the top of the web page, you will find a basic navigation, that routes into two separate pages, where "The Experience" loads the TresCanvas and "Home" is used to unmount the other one.

System Info

No response

Used Package Manager

npm

Code of Conduct

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingp4-important-bugViolate documented behavior or significantly improve performance (priority)performance

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions