As Simon points out, a โstatic classโ means different things in different languages, and Java has nothing like static classes in some other languages, but I donโt think what you are talking about. It seems you are asking if objects referenced by strong static links can collect garbage. If so, the answer is no.
A class is represented by an object of the Class class, accessible through its ClassLoader . Thus, everything that the Class refers to will be available until it reaches ClassLoader , which is the case with the system class loader, as long as Java / Dalvik VM exists. But this is not as long as the phone works, since an independent virtual machine is created for each application. The entire process and the virtual machine in which the application is running can be killed whenever the application is in the background. When you return to the application, its classes will be reloaded.
If static fields are really the best choice, unlike the ContentProvider or foregound Service , then every time your application resumes, you will need to check if the static links have been initialized and reinitialized if they are null.
source share