@@ -97,11 +97,19 @@ class RecordHandler {
97
97
this . _connection = connection
98
98
this . _client = client
99
99
this . _records = new Map ( )
100
+ this . _cache = new Map ( )
100
101
this . _listeners = new Map ( )
101
102
this . _pruning = new Set ( )
102
103
this . _patching = new Map ( )
103
104
this . _updating = new Map ( )
104
105
106
+ this . _registry = new FinalizationRegistry ( ( name ) => {
107
+ const entry = this . _cache . get ( name )
108
+ if ( entry && entry . deref && entry . deref ( ) === undefined ) {
109
+ this . _cache . delete ( name )
110
+ }
111
+ } )
112
+
105
113
this . _connected = 0
106
114
this . _stats = {
107
115
updating : 0 ,
@@ -134,6 +142,11 @@ class RecordHandler {
134
142
for ( const rec of pruning ) {
135
143
rec . _$dispose ( )
136
144
this . _records . delete ( rec . name )
145
+
146
+ if ( ! this . _cache . has ( rec . name ) ) {
147
+ this . _cache . set ( rec . name , new WeakRef ( rec ) )
148
+ this . _registry . register ( rec , rec . name )
149
+ }
137
150
}
138
151
139
152
this . _stats . pruning -= pruning . size
@@ -219,7 +232,7 @@ class RecordHandler {
219
232
let record = this . _records . get ( name )
220
233
221
234
if ( ! record ) {
222
- record = new Record ( name , this )
235
+ record = this . _cache . get ( name ) ?. deref ( ) ?? new Record ( name , this )
223
236
this . _stats . records += 1
224
237
this . _stats . created += 1
225
238
this . _records . set ( name , record )
0 commit comments