Performance: Why IoC matters
MEDIUM IMPACT
IoC affects application startup time and runtime memory usage by managing object creation and dependencies efficiently.
@Service
public class Service {
private final Repository repo;
public Service(Repository repo) {
this.repo = repo;
}
}
// Spring IoC container injects dependenciespublic class Service {
private Repository repo = new Repository();
// manual new object creation inside classes
}| Pattern | Object Creation | Startup Time | Memory Usage | Verdict |
|---|---|---|---|---|
| Manual new object creation | Multiple redundant objects | Higher due to repeated instantiation | Higher memory due to duplicates | [X] Bad |
| IoC container managed beans | Singleton or scoped objects reused | Lower by centralized creation | Lower by sharing instances | [OK] Good |