Skip to content

[Docs/Lifecycle] Document viewer.dispose() — WebGL context leak on reload / SPA nav #96

Description

@SamuelAB-VIM

Environment

  • vim-web 1.0.0-alpha.0, IIFE build (dist/vim-web.iife.js) loaded via <script>
  • API: VIM.Core.Webgl.createViewer() (headless, custom UI)
  • Chromium / desktop, devicePixelRatio 1.75
  • Model: 2,547 elements (2,264 with geometry), 12 Revit categories, structural

Summary. Each createViewer() allocates a WebGL context. Re-creating viewers (hot reload,
route changes, repeated mounts) without disposing leaks contexts. Browsers cap WebGL contexts
(~16); past that the renderer degrades and the page freezes — symptom: JS still responds
but rendering/screenshots hang, no error thrown. We hit exactly this during development.

Fix that resolved it.

window.addEventListener('pagehide', () => viewer.dispose());
// or call viewer.dispose() on component unmount

Asks. Show viewer.dispose() in the quickstart (mount/unmount lifecycle), and consider
warning when the active context count gets high.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions