get.put(someclass(),永久:true)和get.put(somegetXservice())之间的内存管理差异是什么
我正在使用GETX及其依赖注入机制。
有时候我要思考 - 我应该注入一个应该保留在记忆中的班
get.put(someclass(),永久:true)
或使用
get.put(somegetXservice())
通过阅读文档,这两种方式似乎都将班级纳入了Singelton,并且只能明确删除(即不使用get.smartmanagement)。
至于我,我不想使用getxService扩展课程,因为第一个选项更容易实现 - 但我觉得我可能会缺少一些东西。必须将班级作为Singelton在App Life-Span中成为Singelton是必须的。 感谢您的帮助
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个选项始终使整个应用程序的内存保持在内存中,而第二个选项将服务绑定到堆栈导航生命周期。根据getx dpcumentation,a get.Reset()。但是,在大多数情况下,这两种方法都可能同样有效,因为从本质上讲,无论如何,整个应用程序生命周期中的内存都保存在内存中。
The first option always keeps the class in memory throughout the entire app's lifespan, while the second option binds the service to the stack navigation lifecycle. According to GetX dpcumentation, a GetXService is only deleted with a call to
Get.reset()
. In most cases though, both methods will probably be equally valid, since in essence, a service is kept in memory throughout the entire app lifecycle anyways.