-
Notifications
You must be signed in to change notification settings - Fork 152
Description
The use of a DI container comes with a certain increase of memory pressure. This happens because the container must be informed about all registrations and their metadata. This metadata will be kept into memory for the duration of the application and will increase almost constantly with the number of registrations in the application.
All DI containers have this cost and increased memory pressure compared to Pure DI is inevitable. With Simple Injector every registration causes some extra memory that will be kept allocated as long as the container instance is referenced (which usually is for the duration of the application).
For each registration Simple Injector will hold the following information in memory:
- The InstanceProducer (80 bytes by itself) with:
- The generated Expression tree (? bytes)
- Collection of KnownRelationships
- The Registration (25 bytes by itself) with:
- HashSet for KnownRelationsips
This can easily lead up to around 300 bytes per registration. This is memory that will keep being referenced until the Container instance goes out of scope (which typically means the application stops).
Simple Injector is already highly tuned but we might do even more to prevent memory pressure. We should investigate how we can reduce pressure as much as possible.
Currently, the overhead is somewhere between 380 and 400 bytes per unique registration.
Do note, however, that no user has ever complained about the memory use in Simple Injector, and its memory use will likely be similar to other DI Containers, although it would be nice to see a benchmark for this.