none
Will moving code to dlls reduce runtime memory footprint? RRS feed

  • Question

  • I'm trying to reduce the memory footprint of a .net 2.0 windows forms app.  The main assembly includes many classes that could be in separate dll's - would moving much of the classess/code that are less frequently used to separate .Net library files reduce the memory footprint of the exe or are all libraries loaded on initial assembly execution?
    Thanks,
    jim
    Thursday, December 18, 2008 5:36 PM

Answers

  • Tthat depends on how you load the libraries. If you just create references to the libraries in the windows forms app, then they all get loaded at startup. And since each new assembly (library) has it's own metadata header and other requisit bits of info, the memory footprint will ultimately be larger.

    If you load the libraries manually, then you can load only the ones that need to be used. However, this requires a kind of plug-in architecture. But again, if you end up using all of them, then you still haven't reduced the overall memory footprint of the app.

    But more importantly, for an app that is large, the class metadata is most likely dwarfed by the size of the actual object instances that you are creating. So splitting out classes isn't going to do much anyway. You'll have to be more careful in how you create objects. For example, hiding and reusing forms instead of closing and re-creating them over and over, especially if the forms have many controls. You might also benefit from creatively caching data instead of re-creating large sets of data every time you need it.
    -Rob Teixeira
    • Marked as answer by jimNeocasa Thursday, December 18, 2008 7:32 PM
    Thursday, December 18, 2008 5:54 PM

All replies

  • Tthat depends on how you load the libraries. If you just create references to the libraries in the windows forms app, then they all get loaded at startup. And since each new assembly (library) has it's own metadata header and other requisit bits of info, the memory footprint will ultimately be larger.

    If you load the libraries manually, then you can load only the ones that need to be used. However, this requires a kind of plug-in architecture. But again, if you end up using all of them, then you still haven't reduced the overall memory footprint of the app.

    But more importantly, for an app that is large, the class metadata is most likely dwarfed by the size of the actual object instances that you are creating. So splitting out classes isn't going to do much anyway. You'll have to be more careful in how you create objects. For example, hiding and reusing forms instead of closing and re-creating them over and over, especially if the forms have many controls. You might also benefit from creatively caching data instead of re-creating large sets of data every time you need it.
    -Rob Teixeira
    • Marked as answer by jimNeocasa Thursday, December 18, 2008 7:32 PM
    Thursday, December 18, 2008 5:54 PM
  • Thanks very helpful.  I probably could do a better job disposing class instances.  I'm am interested in the library plug model you mentioned as well.  Could you point me in the right direction for more info on that?
    Thanks again,
    jim
    Thursday, December 18, 2008 7:34 PM