get.put(someclass(),永久:true)和get.put(somegetXservice())之间的内存管理差异是什么

发布于 2025-01-30 06:13:19 字数 387 浏览 2 评论 0 原文

我正在使用GETX及其依赖注入机制。

有时候我要思考 - 我应该注入一个应该保留在记忆中的班

get.put(someclass(),永久:true)

或使用

get.put(somegetXservice())

通过阅读文档,这两种方式似乎都将班级纳入了Singelton,并且只能明确删除(即不使用get.smartmanagement)。

至于我,我不想使用getxService扩展课程,因为第一个选项更容易实现 - 但我觉得我可能会缺少一些东西。必须将班级作为Singelton在App Life-Span中成为Singelton是必须的。 感谢您的帮助

I am using Getx and its dependency injection mechanism.

sometime I am overthinking - should I inject a class that should remain in memory (for good as a Singelton) using

Get.put(SomeClass(), permanent: true)

or using

Get.put(SomeGetXService())

by reading the documentation, both ways seems to put the class in memory as Singelton, and it can only be deleted explicitly (i.e. not with Get.smartManagement).

as for me, I prefer not to extend the class with GetxService, since the first option is simpler to implement - but I feel like I might be missing something. having the class in memory as Singelton through out the app life-span is a must.
Thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离不开的别离 2025-02-06 06:13:19

第一个选项始终使整个应用程序的内存保持在内存中,而第二个选项将服务绑定到堆栈导航生命周期。根据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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文