views:

367

answers:

4

Background: At my company we are developing a bunch applications that are using the same core dll's. These dll's are using Spring.net's IoC-container to wire things up (auto-wiring). All applications are using the same spring configuration file, and this configuration file points to many classes in many different dll's. But not all application needs functionality from every dll. But because of the way IoC-containers works, all dll's is loaded for Spring.net to examine the types and check what interfaces they implement and so on.

Core question: I understand that it's better to just load the dll's you really use. But is it really bad for memory usage just to load a managed dll? Or is it first then you are using classes in the dll and they are getting JIT'ed that the most memory are used?

+1  A: 

I don't think it's so bad. Only problem is that because of large metadata and amount of memory your application takes it's more possible that some parts of application which are in use will be located at different memory pages which can 'cause some performance leaks, but it's very low segment of application where this type of things are critical.

dimarzionist
+1  A: 

Really bad is a difficult term to quantify, I guess depends on the scale of things, in general I'd say that if you can avoid loading stuff you don't need then you should. But of course if you are using reflection to determine if you can use it, you first have to load it...chicken and the egg problem.

Something to be aware of though, once you load an assembly into an Application Domain you can't then unload it from that App domain, it is possible however to dynamically create app domains load assemblies into it and unload the whole app domain when you are done.

Tim Jarvis
+1  A: 

If none of the code from the assembly is ever used, then eventually the pages from that assembly will be moved from memory into the page file in favour of actively used pages. In which case, the overall long-term effect is likely to be minor. Although, there will be a negative effect on startup time.

1800 INFORMATION
A: 

Hi,

of course loading dll's w/o using them causes slower startup time due to reading the assembly from disk and evidence/security checks. But if memory is your concern you at least can be sure, you won't waste more memory than the size of your assemblies if you really don't use any types within. Of course if those types are specified in the spring configuration, at least those types get loaded into memory and their static initializer (if any) will be executed. In rare cases this might be an issue. JITing is done on by the CLR on a per-method basis, so methods you do not use won't waste cpu+memory.

In any case you may split your configuration files into partitions e.g. by putting all object definitions of module A into file moduleA.config, all definitions of module B into file moduleB.config and specify only those modules for your particular application that are really needed.

hth, Erich

P.S.: I'd also like to suggest you post Spring for .NET relevant questions to our community forums - it is more likely to get your questions answered there.

Erich Eichinger