Fix NativeEngine memory leak #104
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With React hooks, a state setter can optionally take a lambda that receives the old state value and returns the new state value. We were relying on this to get the old
NativeEngineinstance and dispose it when the containing component is unmounted. However, what I have found is that the state setter lambda is not actually invoked during an unmount, and so we were not disposing theNativeEngineinstance, which resulted in the XR session not being exited or cleaned up, which meant we were leaking a very large amount of memory if theEngineViewis unmounted while in XR mode. Other resources are leaked as well in this scenario, but the XR resources are most noticeable.This change also updates to the latest BabylonNative submodule, which brings in
XMLHttpRequestmemory leak fixes as well.This change (including the BabylonNative update) addresses the bulk of #102.