Java Android中语言环境的弱引用
请检查此代码:Java Android中语言环境的弱引用,java,android,performance,garbage-collection,weak-references,Java,Android,Performance,Garbage Collection,Weak References,请检查此代码: TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Locale loc = null; WeakReference<Locale> locWeak = new WeakReference<Locale>(loc); String country = locWeak.get().getDisplayCountry(new Locale("
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Locale loc = null;
WeakReference<Locale> locWeak = new WeakReference<Locale>(loc);
String country = locWeak.get().getDisplayCountry(new Locale("", tm.getSimCountryIso()));
Log.i(TAG,"Country is: "+country);
我之所以使用WeakReference,是因为我不需要抓住这个对象,因为随着应用的发展,它会变得毫无用处。其次,我需要保持一个干净的记忆,因为我以后需要做一些繁重的任务
如果有人检查此项,请感谢: 在我对类似主题进行研究后,我得出结论,在这个函数中使用WeakReference比使用StrongReference在内存中更昂贵 检查这个链接:这是我在这个问题上的另一个问题。这里有完整的答案
Locale loc = new Locale("",tm.getSimCountryIso());