本文整理匯總了Java中java.lang.ref.WeakReference.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java WeakReference.clear方法的具體用法?Java WeakReference.clear怎麽用?Java WeakReference.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.ref.WeakReference
的用法示例。
在下文中一共展示了WeakReference.clear方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: unregisterCursor
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
* Deregisters a cursor from the list to be notified of changes.
*
* @param cursor the cursor to deregister
*/
protected void unregisterCursor(final Cursor<E> cursor) {
for (final Iterator<WeakReference<Cursor<E>>> it = cursors.iterator(); it.hasNext();) {
final WeakReference<Cursor<E>> ref = it.next();
final Cursor<E> cur = ref.get();
if (cur == null) {
// some other unrelated cursor object has been
// garbage-collected; let's take the opportunity to
// clean up the cursors list anyway..
it.remove();
} else if (cur == cursor) {
ref.clear();
it.remove();
break;
}
}
}
示例2: compressBitmap
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
public static byte[] compressBitmap(String path, int maxSize, int rqsW, int rqsH) {
if (TextUtils.isEmpty(path)) {
return null;
}
try {
WeakReference<Bitmap> bitmap = cprsBmpBySize(path, rqsW, rqsH);
WeakReference<Bitmap> rotatedBmp = autoRotateBitmap(path, bitmap);
if (!(bitmap == null || rotatedBmp == null || bitmap.get() == rotatedBmp.get())) {
((Bitmap) bitmap.get()).recycle();
bitmap.clear();
}
return cprsBmpByQuality(rotatedBmp, maxSize);
} catch (Exception e) {
return null;
}
}
示例3: removeAllInternetConnectivityChangeListeners
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
public void removeAllInternetConnectivityChangeListeners() {
if (mInternetConnectivityListenersWeakReferences == null) {
return;
}
Iterator<WeakReference<InternetConnectivityListener>> iterator = mInternetConnectivityListenersWeakReferences.iterator();
while (iterator.hasNext()) {
WeakReference<InternetConnectivityListener> reference = iterator.next();
if (reference != null) {
reference.clear();
}
iterator.remove();
}
unregisterNetworkChangeReceiver();
}
示例4: instantiateItem
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
@NonNull
@Override
public Object instantiateItem(@NonNull final ViewGroup container, final int position) {
final Fragment mFragment = (Fragment) super.instantiateItem(container, position);
final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position);
if (mWeakFragment != null) {
mWeakFragment.clear();
}
mFragmentArray.put(position, new WeakReference<>(mFragment));
return mFragment;
}
示例5: destroyItem
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
@Override
public void destroyItem(final ViewGroup container, final int position, final Object object) {
super.destroyItem(container, position, object);
final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position);
if (mWeakFragment != null) {
mWeakFragment.clear();
}
}
示例6: destroyItem
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
WeakReference<Fragment> weakFragment = weakFragmentMap.get(position);
if (weakFragment != null) {
weakFragment.clear();
}
}
示例7: changeDataset
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
public void changeDataset() {
for (int i = 0; i < weakFragmentMap.size(); i++) {
WeakReference<Fragment> weakFragment = weakFragmentMap.valueAt(i);
if (weakFragment != null) {
weakFragment.clear();
}
}
notifyDataSetChanged();
}
示例8: remove
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
public XulDrawable remove(String key) {
WeakReference<XulDrawable> xulDrawableWeakReference = _cache.remove(key);
if (xulDrawableWeakReference == null) {
return null;
}
XulDrawable xulDrawable = xulDrawableWeakReference.get();
xulDrawableWeakReference.clear();
return xulDrawable;
}
示例9: removeInternetConnectivityChangeListener
import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
* remove the weak reference to the listener
*/
public void removeInternetConnectivityChangeListener(InternetConnectivityListener internetConnectivityListener) {
if (internetConnectivityListener == null) {
return;
}
if (mInternetConnectivityListenersWeakReferences == null) {
return;
}
Iterator<WeakReference<InternetConnectivityListener>> iterator = mInternetConnectivityListenersWeakReferences.iterator();
while (iterator.hasNext()) {
//if weak reference is null then remove it from iterator
WeakReference<InternetConnectivityListener> reference = iterator.next();
if (reference == null) {
iterator.remove();
continue;
}
//if listener referenced by this weak reference is garbage collected then remove it from iterator
InternetConnectivityListener listener = reference.get();
if (listener == null) {
reference.clear();
iterator.remove();
continue;
}
//if listener to be removed is found then remove it
if (listener == internetConnectivityListener) {
reference.clear();
iterator.remove();
break;
}
}
//if all listeners are removed then unregister NetworkChangeReceiver
if (mInternetConnectivityListenersWeakReferences.size() == 0) {
unregisterNetworkChangeReceiver();
}
}