本文整理汇总了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;
}