[M3] GPUDevice leak on the cancelled-before-init path #24

Closed
opened 2026-06-27 03:54:47 +00:00 by sessamekesh · 0 comments
Owner

File: packages/viewer-react/src/IgviewerContext.tsx (IgviewerSession)

If the effect is torn down before acquireIgviewerModule resolves:

  1. The cleanup function (line 276) captures the (still empty) extraCleanup array and reassigns extraCleanup = [].
  2. The async IIFE later resolves, sees cancelled, pushes the device-destroying cleanup onto the new array, and returns early (line 209).
  3. Nothing ever runs that new array.

Impact: an internally-created GPUDevice (when no device prop was supplied) is never .destroy()-ed on a fast mount/unmount — a GPU resource leak.

Fix: run the captured cleanup callbacks in the cancelled branch too (destroy the device before the early return).


Filed by an automated AI code review (manual proof-of-concept run). Code locations reference the various-cleanup branch.

**File:** `packages/viewer-react/src/IgviewerContext.tsx` (`IgviewerSession`) If the effect is torn down before `acquireIgviewerModule` resolves: 1. The cleanup function (line 276) captures the (still empty) `extraCleanup` array and reassigns `extraCleanup = []`. 2. The async IIFE later resolves, sees `cancelled`, pushes the device-destroying `cleanup` onto the **new** array, and returns early (line 209). 3. Nothing ever runs that new array. **Impact:** an internally-created `GPUDevice` (when no `device` prop was supplied) is never `.destroy()`-ed on a fast mount/unmount — a GPU resource leak. **Fix:** run the captured cleanup callbacks in the cancelled branch too (destroy the device before the early return). --- _Filed by an automated AI code review (manual proof-of-concept run). Code locations reference the `various-cleanup` branch._
Sign in to join this conversation.
No description provided.