getx icon indicating copy to clipboard operation
getx copied to clipboard

Memory leaks

Open David20082012 opened this issue 1 year ago • 1 comments
trafficstars

ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION. Fill in the template. Issues that do not respect the model will be closed.

Describe the bug Class Controller extends GetxController{ Static final Controller instance = GET.find(); Int count =0; }

Calling it by :- Controller.instance.count;

When called from and where in the app and it was the reason for creating and initializing the controller , the controller and it's variables won't be deleted or cleared after dispose the controller , the entire controller will be in memory even after applying on delete when removing routes.

David20082012 avatar Dec 26 '23 15:12 David20082012

Hi, I believe there is no memory leak problem in your description, you created a final static variable, it behaves like this. I think perhaps what you intended to do was a static get

''' static YourController get controller => Get.find(); '''

I don't know where you saw that you could use GetX in the way you described, but this was literally creating a singleton of your controller. The intention of GetX is precisely to reduce or completely eliminate singletons that remain forever in memory, and for this purpose a single global variable is used to manage the instances. Avoid "static final" unless you are sure that is what you want. 'static Type get' is what you need

jonataslaw avatar Dec 26 '23 23:12 jonataslaw