close_ sinks
Learn about the close_sinks linter rule.
Close instances of dart:core Sink.
Details
# DO invoke close on instances of dart:core Sink.
Closing instances of Sink prevents memory leaks and unexpected behavior.
BAD:
class A { IOSink _sinkA; void init(filename) { _sinkA = File(filename).openWrite(); // LINT } } BAD:
void someFunction() { IOSink _sinkF; // LINT } GOOD:
class B { IOSink _sinkB; void init(filename) { _sinkB = File(filename).openWrite(); // OK } void dispose(filename) { _sinkB.close(); } } GOOD:
void someFunctionOK() { IOSink _sinkFOK; // OK _sinkFOK.close(); } Known limitations
This rule does not track all patterns of Sink instantiations and closures. See sdk#57882 for more information.
Enable
# To enable the close_sinks rule, add close_sinks under linter > rules in your analysis_options.yaml file:
linter: rules: - close_sinks If you're instead using the YAML map syntax to configure linter rules, add close_sinks: true under linter > rules:
linter: rules: close_sinks: true Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Report an issue.