File tree Expand file tree Collapse file tree
packages/@glimmer/destroyable Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -183,6 +183,12 @@ export function destroy(destroyable: Destroyable) {
183183 } ) ;
184184
185185 meta . state = DESTROYED_STATE ;
186+
187+ // Release references so GC can reclaim the destroyed tree
188+ meta . parents = null ;
189+ meta . children = null ;
190+ meta . eagerDestructors = null ;
191+ meta . destructors = null ;
186192 } ) ;
187193}
188194
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { DEBUG } from '@glimmer/env';
22import type { GlobalContext } from '@glimmer/global-context' ;
33import { unwrap } from '@glimmer/debug-util' ;
44import {
5+ _hasDestroyableChildren ,
56 assertDestroyablesDestroyed ,
67 associateDestroyableChild ,
78 destroy ,
@@ -384,6 +385,23 @@ module('Destroyables', (hooks) => {
384385 assert . verifySteps ( [ 'child destructor' , 'parent destructor' ] , 'destructors run bottom up' ) ;
385386 } ) ;
386387
388+ test ( 'metadata children reference is cleared after destruction completes' , ( assert ) => {
389+ const parent = { } ;
390+ const child = { } ;
391+
392+ associateDestroyableChild ( parent , child ) ;
393+
394+ assert . true ( _hasDestroyableChildren ( parent ) , 'parent has children before destruction' ) ;
395+
396+ destroy ( parent ) ;
397+ flush ( ) ;
398+
399+ assert . false (
400+ _hasDestroyableChildren ( parent ) ,
401+ 'parent metadata clears children reference after destruction, allowing GC to reclaim the tree'
402+ ) ;
403+ } ) ;
404+
387405 if ( DEBUG ) {
388406 test ( 'attempting to unregister a destructor that was not registered throws an error' , ( assert ) => {
389407 assert . throws ( ( ) => {
You can’t perform that action at this time.
0 commit comments