Skip to content Skip to sidebar Skip to footer

Is Passing Context As A Parameter To A Method In A Singleton Class Causes Memory Leak

I'm declaring a Singleton class where I need to pass context parameter for one of the methods in this class public class MySingleton() { Private Context mContext; Private s

Solution 1:

It could, as you do not know what sort of Context you will be referencing. It would be safer to write:

this.mContext = context.getApplicationContext();

This way, you are certain that mContext is referencing the Application singleton.

Post a Comment for "Is Passing Context As A Parameter To A Method In A Singleton Class Causes Memory Leak"