I'm a newbie in dagger 2 and dependence injection in android. I'm hearing that a lot of android developers use dagger 2. I understand that It manages dependencies between classes and with it we will not use anymore the keyword "new" but I want to know why should I use it really? Does it manage memory allocation and minimize leaks? Does it benefit the performance of the application?
I want to concentrate on memory and performance of the application with dependency injection. So, I found this answer in android developer website. https://developer.android.com/topic/performance/memory.html#DependencyInjection :
Use Dagger 2 for dependency injection frameworks
can simplify the code you write and provide an adaptive environment that's useful for testing and other configuration changes.
If you intend to use a dependency injection framework in your app, consider using Dagger 2. Dagger does not use reflection to scan your app's code. Dagger's static, compile-time implementation means that it can be used in Android apps without needless runtime cost or memory usage.
Other dependency injection frameworks that use reflection tend to initialize processes by scanning your code for annotations. This process can require significantly more CPU cycles and RAM, and can cause a noticeable lag when the app launches.