Question

Does Using Namespace; consume more memory?

I'm currently working on a mobile application and I was just curious if those unneeded using statements that visual studio places when creating a class make my application require some extra memory to run.

Was it helpful?

Solution

To put it simply: no.

Those statements aren't translated into any form of IL. They're just shortcuts to avoid using (ugly!) fully qualified type names. But, if you're using VS2008 and/or R# you can remove unused ones automagically.

OTHER TIPS

Namespaces are a compile-time only feature of C# that allow you to save time during development. The using directives are utilized by the compiler to look up shorthand Type names in your code.

Basically each time the compiler encounters a type name in your code that it does not know it takes each using directive and prepends it to the type's name and sees if that fully qualified name resolves.

Once you application is compiled the namespaces and the using directives are gone as the IL does not need them.

If by "memory" you mean "I have to remember why I put those using statements at the top in the first place" then yes.

But, no not in the sense you mean. .NET assemblies are typically loaded on-demand, so you won't incur any performance penalty by having those extra statements. However, for the sake of maintainability, you'll want to remove them.

here's the microsoft information on the "using" keyword in this context: http://msdn.microsoft.com/en-us/library/sf0df423.aspx. it basically provides an alternative to using the fully qualified name on an assembly, but it doesn't actually import or include the assemblies in memory with that particular keyword.

No, it does not. It simply is a shorthand to allow you to use only the type name

StringBuilder

As opposed to the namespace-qualified type name:

System.Text.StringBuilder

In the file where the using statement is declared.

No, it will only make the compiler run a tiny bit slower :)

It does not. It is used so that you do not have to define the object you are using by your full name. Instead of System.IO.File you can just do File if you are using System.IO.

It is not loaded into the memory until you actually create the object. Unlike C++ the entire library is not imported, because the .NET framework is installed on the target machine and loaded in the GAC, and your custom .dll are in the bin folder of the application folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top