I’m using reflection for inspection purposes only and don’t create many objects. Does this affect the working set?
Even if you don’t instantiate the types you reflect on, using reflection functionality may result in a significant permanent working set hit. For example, GetTypes() causes all the types defined in an assembly to be loaded, which means the .NET Compact Framework common language runtime loader will create an internal in-memory representation for each one of these types. These internal runtime structures remain alive until AppDomain shutdown (which essentially means they never get unloaded in version 1.0). Although those individual structures are not very large (the total memory associated with each loaded type is : ~70 bytes + (number of fields * 8 bytes) + (number of methods * 4 bytes), so you can easily be spending over 100 bytes per loaded type), if the number of them is high enough, unnecessary loading can result in a substantial permanent memory hit. This should also be a consideration when enumerating methods and properties of the type.
Related Questions
- I’m interested in working in the restaurant business but don’t have a California Food Handler Card yet. Does it matter?
- I’m using reflection for inspection purposes only and don’t create many objects. Does this affect the working set?
- I’m working at Central or Central District Office but I don’t want to drive. What are my other options?