Here is a similar question but I think it is not identical
And I read Setting up request queue tutorial here
In this page they write the following code
public class MySingleton {
private static Context mCtx;
And I wrote same code in my project
public class VolleySingleton {
private static Context mContext;
Android studio say “Do not place Android context classes in static fields; this is a memory leak”.
What does it mean? And why dos the official android developer website use such kind of code?
try this? `
Let say You are referencing your class
MySingleton
from another class and yourMySingleton
Class has been destroyed by the OS but thestatic Context(mContext)
is still in use by some activity so this will hold on thecontext
from garbage collection unless you set yourMySingleton
reference inside your activity tonull
and this will leak all the application's resources