Reduce memory pressure #347

dotnetjunkie opened this Issue Dec 15, 2016 · 0 comments


None yet

1 participant


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 inevetable. 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 referenced until 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.

@dotnetjunkie dotnetjunkie added this to the Backlog milestone Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment