Skip to content

Commit c7cfa90

Browse files
committed
perf(logger): clean up constructor args after Console initialization
Added memory cleanup by deleting constructor args from WeakMap after Console is initialized. Once the Console is created, the constructor arguments are no longer needed and can be garbage collected. Changes: - Added privateConstructorArgs.delete(this) in #getConsole() - Added cleanup in dynamic console method initialization - Reduces memory footprint for long-lived logger instances
1 parent 917930d commit c7cfa90

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/logger.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ export class Logger {
391391
}
392392
}
393393
privateConsole.set(this, con)
394+
// Clean up constructor args - no longer needed after Console creation.
395+
privateConstructorArgs.delete(this)
394396
}
395397
return con
396398
}
@@ -1559,7 +1561,7 @@ Object.defineProperties(
15591561
// Access Console via WeakMap directly since private methods can't be
15601562
// called from dynamically created functions.
15611563
let con = privateConsole.get(this)
1562-
if (!con) {
1564+
if (con === undefined) {
15631565
// Lazy initialization - this will only happen if someone calls a
15641566
// dynamically added console method before any core logger method.
15651567
const constructorArgs = privateConstructorArgs.get(this) || []
@@ -1575,6 +1577,8 @@ Object.defineProperties(
15751577
}
15761578
}
15771579
privateConsole.set(this, con)
1580+
// Clean up constructor args - no longer needed after Console creation.
1581+
privateConstructorArgs.delete(this)
15781582
}
15791583
const result = (con as any)[key](...args)
15801584
return result === undefined || result === con ? this : result

0 commit comments

Comments
 (0)