It seems to me that you need to use the functions that a suitable dependency injection infrastructure can give you. Do not use other constructive logic for testing / production.
When using spring, single injections are only performed when the container starts. Prototype injections are performed every time. Full wiring is also performed every time you run unit test, if connected. Thus, profiling tests are usually not a good idea.
Perhaps you are using too few single core areas and too much prototype? (Prototype = new instance every time)
The attractive thing about spring injection is that you can use proxy objects, i.e. your object graph might look like this:
A Singleton | B Singleton | C Prototype (per-invocation) | D Singleton | E Session scope (web app) | F Singleton
And each request will create only one instance of C and one instance of E per session. A, B, D and F are single. If this is not a webapp, you do not have a default session area, but you can also create your own areas (the Window area sounds cool for a windowed desktop). The key here is that you can “enter” areas at any level, effectively you can have ten layers of singleton objects, and suddenly something session appears. (It can really revolutionize how you implement some cross-cutting features in layered architecture, but that's a different story)
This really gives the smallest possible object creation inside the DI model. I think.
Although this is spring for Java, I believe a number of other DI frameworks should support similar features. Perhaps not the most minimalist.
krosenvold
source share