Skip to content

Memory leak when switching cameras #270

@Pinpickle

Description

@Pinpickle

When switching cameras, a small amount of memory is leaked. This is enough to get Safari to crash on an iPhone 13 Pro after enough switches (somewhere between 500 and 1,000) on a simple scene.

Recording from an iPhone

It crashes about halfway through, auto-reloads, then crashes again and refuses to reload. This is due to running out of memory.

Warning: the video and reproduction strobe a bit as it changes the camera 100 times per second to speed up the crash.

RPReplay_Final1711087455.mov

Reproduction

Here's the reproduction: https://stackblitz.com/edit/vitejs-vite-khvsd4?file=src%2FApp.tsx

To run it on your phone, you'll need to pull the stackblitz down and run it locally (npm install then npm run dev), then open it on your phone via the local network.

Misc comments

With a more complex app, I am able to crash the app in ~10 camera switches with an empty EffectComposer. I can't work out exactly what is causing the increase in memory consumption in the more complex case.

I think this is due to the fact that for every camera/scene change, the useMemo call in EffectComposer creates a new instance without disposing the old one, thus keeping all of the textures for the passes around.

}, [
camera,
gl,
depthBuffer,
stencilBuffer,
multisampling,
frameBufferType,
scene,
enableNormalPass,
resolutionScale,
])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions