Dispose Pattern (ARCH3082)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key typescript.performance.dispose-pattern · Severity warning · Category performance
If a class holds closeable/disposable fields but does not implement the cleanup contract, the resources it owns are never released.
Incorrect
Section titled “Incorrect”class Logger { private stream = fs.createWriteStream("log.txt");
write(msg: string): void { this.stream.write(msg); } // no dispose - stream leaks}Correct
Section titled “Correct”class Logger implements Disposable { private stream = fs.createWriteStream("log.txt");
write(msg: string): void { this.stream.write(msg); }
[Symbol.dispose](): void { this.stream.close(); }}Implement the cleanup contract (Disposable) on classes holding closeable fields and release the owned resources.