If I refer a namespaces in a program, but don't use anything from that namespace, will it waste memory ?
Printable View
If I refer a namespaces in a program, but don't use anything from that namespace, will it waste memory ?
Yes, but a minimal amount at runtime. The only real penalty is if you reference lots of unneeded namespaces intelisense will take a while to populate in the DE.Quote:
Originally Posted by iPrank
Thanks ! :thumb:
As I understand the compiler strips out unreferenced namespaces so the EXE is as clean as possible. Using statements are only used by the c# preprocesor.
OK. I'm confused. :D
I searched google, but didn't find anything usefull.
PS: I've made this thread 'unresolved'.
As far as I'm aware the "using" statement only affects the design time experience. It allows you to refer to types in your code without qualifying them with their namespace. Once your code is compiled that makes no difference because the MSIL will be the same regardless of whether you have qualified your types or not. It is referencing assemblies that may cause an issue. If you add a reference to your project to an assembly then that assembly will be loaded at run time. If you don't use any types from that assembly then you've wasted the memory it's occupying. It may be that the compiler is smart enough to remove unused references but I'm not sure if that's the case. Perhaps that's what wossname was referring to. Namespaces and assemblies are not the same thing though. A namespace is just a logical classification of types and doesn't actually exist in any particular place. A single namespace may be spread over more than one assembly.
Thanks guys ! :)
Edit: Damn ! Woosy and John, I can't rate you in this thread. :(
Hopefully I'll be using Mono in linux soon so can once again join in the fun of C# coding at home as well as at work.
I'm buying a new hard disk today. I'll get some free space to install Linux again. :D