android - Dagger 2 对性能有什么好处吗?

标签 android dagger

<分区>

我是 dagger 2 和 android 依赖注入(inject)的新手。我听说很多 android 开发人员使用 dagger 2。我知道它管理类之间的依赖关系,有了它我们将不再使用关键字“new”,但我想知道为什么我真的要使用它?它是否管理内存分配并最大限度地减少泄漏?它对应用程序的性能有好处吗?

最佳答案

我想专注于依赖注入(inject)应用程序的内存和性能。所以,我在 android 开发者网站上找到了这个答案。 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.

关于android - Dagger 2 对性能有什么好处吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47080773/

相关文章:

android - JUnit TestRule 中的 Dagger 注入(inject)

java - Dagger 错误 : Can't inject a non-static inner class

Android Studio 插件异常

android - 使用 AppCompat 时如何更改 ActionBar 标题字体

android - 在没有 Android 框架的情况下创建 Android 应用程序

javascript - React Native setState() 和 Android 上的动画

java - Dagger 2 没有生成类

android - 带有模块排除的 gradle 依赖属性

java - Android “setSelected()” 和 "setChecked() 之间的区别

android - 从 Android Studio 的全局搜索中删除 Dagger 生成的类?