Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android中语言环境的弱引用_Java_Android_Performance_Garbage Collection_Weak References - Fatal编程技术网

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());