Dart allows circular import.
My general understanding was that cyclical import (file a import file b, file b import file a) was a bad practice, generally to let go resources, and garbage collection. However there is not even a warning in dart so I'm left wondering if it can lead to undesired behavior or not.
Does it have an effect on garbage collection. Can it lead to issues ?
CodePudding user response:
Dart uses circular imports to support multi-pass compilers which processes source code multiple times to create intermediary code. Dart VM also supports Just In Time Compiling and Ahead of time compiling which uses this intermediate code.
The JIT compiler converts the source code into native machine code before execution to improve performance speed and runtime. Its used in Java as well.
The AOT compiler enforces the type system Dart uses and manages memory using fast object allocation and a generational garbage collector which is what supports these circular imports. It is used when your app is ready to be deployed for production. It compiles the code before its delivered to whatever runtime environment will run it.
CodePudding user response:
I do this quite a lot actually and it never caused any problems.
Edit: This answers the question quite well: Dart - Circular imports