File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 303
303
304
304
// func finalizeRef(v ref)
305
305
"syscall/js.finalizeRef" : ( v_ref ) => {
306
- // Note: TinyGo does not support finalizers so this should never be
307
- // called.
308
- console . error ( 'syscall/js.finalizeRef not implemented' ) ;
306
+ // Note: TinyGo does not support finalizers so this is only called
307
+ // for one specific case, by js.go:jsString. and can/might leak memory.
308
+ const id = mem ( ) . getUint32 ( unboxValue ( v_ref ) , true ) ;
309
+ // Note that this if is so far seemingly never true. Someone should investigate why.
310
+ if ( this . _goRefCounts ?. [ id ] !== undefined ) {
311
+ this . _goRefCounts [ id ] -- ;
312
+ if ( this . _goRefCounts [ id ] === 0 ) {
313
+ const v = this . _values [ id ] ;
314
+ this . _values [ id ] = null ;
315
+ this . _ids . delete ( v ) ;
316
+ this . _idPool . push ( id ) ;
317
+ }
318
+ } else {
319
+ // Log as a hint and reminder that something is probably off.
320
+ console . log ( "syscall/js.finalizeRef: unknown id" , id ) ;
321
+ }
309
322
} ,
310
323
311
324
// func stringVal(value string) ref
You can’t perform that action at this time.
0 commit comments