Answer the question
In order to leave comments, you need to log in
Static Handler in activity causes memory leak?
There is a main activity, in it the main fragment in which several more fragments change in turn. When trying to call a method in a parent fragment using getParentFragment() from its child fragments - throws an error. The documentation says that if the fragment is attached to the activity, then the method returns null. And I decided to create a static Handler to run methods in the main activity, from its child fragment, and a non-static Handler to run the methods of this fragment from its lower child fragments. Everything works, but does it lead to a memory leak? Activity never closes (no transitions between activities), only fragments in this activity change
Answer the question
In order to leave comments, you need to log in
if MainActivity
should not if onCreate handler replace.
You can also make handler = null in onDestroy
In general, check. At least monitor the memory when you rotate the screen.
...the main fragment in which several more fragments change in turn. When trying to call a method in a parent fragment using getParentFragment() from its child fragments - throws an error.
With getActivity () - it is clear. It works and the methods from the child fragment are called. But this child fragment has its own child fragments which are already throwing an error on getParentFragment() since it works in the activity. And in order not to get confused in the ways of calling parent functions, I decided to make one approach for everything (that is, static handlers that are visible from afar, and to which messengers can be sent). I read in some article that static handlers have implicit links to activities and fragments, but these links are called "weak", so they are removed by the garbage collector and do not lead to leaks. In the application manager of the phone, with a program weight of 5 mb, sometimes a weight of 20-40 mb is displayed there, and I don’t understand what this means. Image processing application.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question