本文整理匯總了Java中java.lang.ref.SoftReference.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java SoftReference.clear方法的具體用法?Java SoftReference.clear怎麽用?Java SoftReference.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.ref.SoftReference
的用法示例。
在下文中一共展示了SoftReference.clear方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDirectByteBuffer
import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private static ByteBuffer getDirectByteBuffer()
{
// Since direct buffers are allocated outside of the heap they can behave strangely in relation to GC
// So we try to make them as long-lived as possible and cache them in a ThreadLocal
ByteBuffer buffer = null;
int blockSize = getBlockSize();
SoftReference<ByteBuffer> reference = DiskDataStorage.threadLocal.get();
if (reference != null)
{
buffer = reference.get();
if (buffer != null && buffer.capacity() != blockSize)
{
// Clear references to the direct buffer so it may be GC'd
reference.clear();
buffer = null;
}
}
if (buffer == null)
{
buffer = ByteBuffer.allocateDirect(blockSize);
reference = new SoftReference<ByteBuffer>(buffer);
DiskDataStorage.threadLocal.set(reference);
}
return buffer;
}
示例2: closeOldLoaders
import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private void closeOldLoaders() throws IOException {
SoftReference<Closeable> ref = loadersToClose.poll();
while (ref != null) {
Closeable closeable = ref.get();
if (closeable != null) {
closeable.close();
}
ref.clear();
ref = loadersToClose.poll();
}
}
示例3: put
import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public AnyObject put(Long key, AnyObject value) {
SoftReference<AnyObject> softReference = cacheMap.put(key, new SoftReference<>(value));
if (softReference != null) {
AnyObject o = softReference.get();
softReference.clear();
return o;
} else {
return null;
}
}
示例4: remove
import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public AnyObject remove(Long key) {
SoftReference<AnyObject> softReference = cacheMap.remove(key);
//напишите тут ваш код
if (softReference != null) {
AnyObject o = softReference.get();
softReference.clear();
return o;
} else {
return null;
}
}
示例5: makeImage
import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private static SoftReference<CachedImage> makeImage(CachedTeXFormula cached)
throws ParseException {
TeXFormula formula = new TeXFormula(cached.f);
TeXIcon icon = formula.createTeXIcon(cached.style, cached.size,
cached.type, cached.fgcolor);
icon.setInsets(new Insets(cached.inset, cached.inset, cached.inset,
cached.inset));
Bitmap image = Bitmap.createBitmap(icon.getIconWidth(),
icon.getIconHeight(), Config.ARGB_8888);
Canvas g2 = new Canvas(image);
icon.paintIcon(g2, 0, 0);
cached.setDimensions(icon.getIconWidth(), icon.getIconHeight(),
icon.getIconDepth());
SoftReference<CachedImage> img = new SoftReference<CachedImage>(
new CachedImage(image, cached), queue);
if (cache.size() >= max) {
Reference soft;
while ((soft = queue.poll()) != null) {
CachedImage ci = (CachedImage) soft.get();
if (ci != null) {
cache.remove(ci.cachedTf);
}
}
Iterator<CachedTeXFormula> iter = cache.keySet().iterator();
if (iter.hasNext()) {
CachedTeXFormula c = iter.next();
SoftReference<CachedImage> cachedImage = cache.get(c);
if (cachedImage != null) {
cachedImage.clear();
}
cache.remove(c);
}
}
cache.put(cached, img);
return img;
}
示例6: flush
import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
* Flushes the cached object. Forces the next invocation of get() to
* invoke reconstitute().
*/
public synchronized void flush() {
SoftReference s = soft;
if (s != null) s.clear();
soft = null;
}
示例7: flush
import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
* Flushes the cached object. Forces the next invocation of get() to
* invoke reconstitute().
*/
public synchronized void flush() {
SoftReference<Image> s = soft;
if (s != null) s.clear();
soft = null;
}