performance - Possible to free Context from Singleton in Android to prevent memory leak -
i'm maintaining legacy project can't refactoring due limitations. found possible memory leak in below scenario.
pass fragment singleton class
foo.getinstance().setbar(fragment);
assuming static instance lives longer need it, approach null in ondestroy() method in fragment.
@override public void ondestroy(){ foo.getinstance().setbar(null);//to prevent memory leak super.ondestroy(); }
i'm new memory leak area, correct me if there wrong :)
use weakreference
in singleton
Comments
Post a Comment