<p>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.</p>

<p>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?</p>

[{'answer_id': 70135, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 1, 'selected': False, 'text': "<p>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. </p>\n"}, {'answer_id': 70141, 'author': 'Tim Jarvis', 'author_id': 10387, 'author_profile': 'https://Stackoverflow.com/users/10387', 'pm_score': 1, 'selected': False, 'text': "<p>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 <em>can</em> use it, you first have to load it...chicken and the egg problem.</p>\n\n<p>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.</p>\n"}, {'answer_id': 70259, 'author': '1800 INFORMATION', 'author_id': 3146, 'author_profile': 'https://Stackoverflow.com/users/3146', 'pm_score': 2, 'selected': True, 'text': '<p>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.</p>\n'}, {'answer_id': 411110, 'author': 'Erich Eichinger', 'author_id': 51264, 'author_profile': 'https://Stackoverflow.com/users/51264', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n\n<p>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.</p>\n\n<p>hth,\nErich</p>\n\n<p>P.S.: I\'d also like to suggest you post Spring for .NET relevant questions to our <a href="http://forum.springframework.net/" rel="nofollow noreferrer">community forums</a> - it is more likely to get your questions answered there.</p>\n'}]
['https://Stackoverflow.com/questions/70098', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4422/']