Reputation: 136
Is there any significant cost to using a reference to a namespace you don't need? I'm thinking the members probably live on the heap somewhere, tying up memory. The reason I ask is because I noticed some old references I no longer need in some production code and am wondering if it is worth refactoring in the short term.
Upvotes: 4
Views: 262
Reputation: 887413
Not at all.
Namespaces and using
statements are a purely compile-time construct.
At runtime, all references to classes and members refer to the actual member including the full namespace.
Extra using
statements will have a minute impact on compile time, since the compiler will need to search more namespaces for each classname.
Unused assemblies also have no impact; assemblies aren't loaded until they're used.
Upvotes: 5