[FEA] Closes some resources in withResource
early after being used
#11713
Labels
good first issue
Good for newcomers
reliability
Features to improve reliability or bugs that severly impact the reliability of the plugin
Is your feature request related to a problem? Please describe.
When using
withResource
to manage resources, we'd better close the resource just after it's used, to reduce peak memory usage. For example, the following code (inGpuCast.scala
)can be rewritten as
to close
childView
early after being used.There are some other cases in our codebase we can improve in this way.
Describe the solution you'd like
I wrote a simple checker script to find such cases. It is just based on some regex and hand-written rules, so some cases may be missed and some false positives may be reported.
Here is the report, we can check and fix them manually, to reduce the chance of GPU OOM.
Describe alternatives you've considered
Ideally the checker can be integrated into the build process, so that we can find such cases automatically. Maybe it should be based on some AST analysis and be a real static analysis tool, but I'm really not an expert in programming language.
The text was updated successfully, but these errors were encountered: