androidapplicationcontextjava-memory-leaks

Android - Can Application Context Solve Memory Leaks?


Using the longest-lived context instead of Activity context should be a good practice to avoid memory leaks when configuration (screen orientation, default language) change. However, I think these objects which reference to Application context still consume an amount of the Heap memory. So when they are released? If they are released when the process is ended, are they considered as a type of memory leaks?


Solution

  • The application context will not be released until the application is destroyed, regardless of whether you hold on to a reference to it or not.