soft-references

How to cause soft references to be cleared in Java?

我只是一个虾纸丫 提交于 2019-11-30 06:43:07
问题 I have a cache which has soft references to the cached objects. I am trying to write a functional test for behavior of classes which use the cache specifically for what happens when the cached objects are cleared. The problem is: I can't seem to reliably get the soft references to be cleared. Simply using up a bunch of memory doesn't do the trick: I get an OutOfMemory before any soft references are cleared. Is there any way to get Java to more eagerly clear up the soft references? Found here

How to cause soft references to be cleared in Java?

和自甴很熟 提交于 2019-11-28 21:18:47
I have a cache which has soft references to the cached objects. I am trying to write a functional test for behavior of classes which use the cache specifically for what happens when the cached objects are cleared. The problem is: I can't seem to reliably get the soft references to be cleared. Simply using up a bunch of memory doesn't do the trick: I get an OutOfMemory before any soft references are cleared. Is there any way to get Java to more eagerly clear up the soft references? Found here : "It is guaranteed though that all SoftReferences will get cleared before OutOfMemoryError is thrown,

Is there a SoftHashMap in Java?

可紊 提交于 2019-11-28 15:46:44
I know there is a WeakHashMap in java.util , but since it uses WeakReference s for everything, which is only referenced by this Map , referenced objects will get lost on the next GC cycle. So it's nearly useless if you want to cache random data, which is very likely to be requested again without being Hard-linked the rest of the time. The best solution would be a map, which uses SoftReference s instead, but I didn't find one in the Java RT Package. VonC Edit (Aug. 2012): It turns out that currently the best solution are probably Guava 13.0's Cache classes, explained on Guava's Wiki - that's

Is there any way to make a soft reference or Pointer-like objects using Numpy arrays?

人走茶凉 提交于 2019-11-28 13:46:20
I was wondering whether there is a way to refer data from many different arrays to one array, but without copying it. Example: import numpy as np a = np.array([2,3,4,5,6]) b = np.array([5,6,7,8]) c = np.ndarray([len(a)+len(b)]) offset = 0 c[offset:offset+len(a)] = a offset += len(a) c[offset:offset+len(b)] = b However, in the example above, c is a new array, so that if you modify some element of a or b , it is not modified in c at all. I would like that each index of c (i.e. c[0] , c[1] , etc.) refer to each element of both a and b , but like a pointer, without making a deepcopy of the data.

Why doesn't .NET have a SoftReference as well as a WeakReference, like Java?

谁都会走 提交于 2019-11-28 11:56:35
I really love WeakReference's. But I wish there was a way to tell the CLR how much (say, on a scale of 1 to 5) how weak you consider the reference to be. That would be brilliant. Java has SoftReference, WeakReference and I believe also a third type called a "phantom reference". That's 3 levels right there which the GC has a different behaviour algorithm for when deciding if that object gets the chop. I am thinking of subclassing .NET's WeakReference (luckily and slightly bizzarely it isn't sealed) to make a pseudo-SoftReference that is based on a expiration timer or something. Adam Gawne-Cain

SoftReference gets garbage collected too early

柔情痞子 提交于 2019-11-28 06:34:58
I'm on my way with implementing a caching mechanism for my Android application. I use SoftReference , like many examples I've found. The problem is, when I scroll up or down in my ListView , the most of the images are already cleared. I can see in LogCat that my application is garbage collected everytime the application loads new images. That means that the most of the non-visible images in the ListView are gone. So, everytime I scroll back to an earlier position (where I really downloaded images before) I have to download the images once again - they're not cached . I've also researched this

How to make the java system release Soft References?

一个人想着一个人 提交于 2019-11-27 20:39:08
I'm going to use a SoftReference-based cache (a pretty simple thing by itself). However, I've came across a problem when writing a test for it. The objective of the test is to check if the cache does request the previously cached object from the server again after the memory cleanup occurs. Here I find the problem how to make system to release soft referenced objects. Calling System.gc() is not enough because soft references will not be released until the memory is low. I'm running this unit test on the PC so the memory budget for the VM could be pretty large. ================== Added later ==

Is there a SoftHashMap in Java?

依然范特西╮ 提交于 2019-11-27 19:51:30
问题 I know there is a WeakHashMap in java.util , but since it uses WeakReference s for everything, which is only referenced by this Map , referenced objects will get lost on the next GC cycle. So it's nearly useless if you want to cache random data, which is very likely to be requested again without being Hard-linked the rest of the time. The best solution would be a map, which uses SoftReference s instead, but I didn't find one in the Java RT Package. 回答1: Edit (Aug. 2012): It turns out that

Android: Bitmaps, SoftReferences, and OOMs?

谁说我不能喝 提交于 2019-11-27 15:37:02
问题 I have a series of views in a vertical LinearLayout. Each view generates and draws a Bitmap, when scrolled to. For performance reasons, I would rather not generate the Bitmap each time onDraw() is called, but for memory reasons I can not keep hard references to the Bitmaps. I could use advice on the strategy that I should take. I already tried the obvious route of: generating the Bitmap, and then wrapping it with a SoftReference. This failed for two reasons. 1. The references get collected

Is there any way to make a soft reference or Pointer-like objects using Numpy arrays?

怎甘沉沦 提交于 2019-11-27 07:55:04
问题 I was wondering whether there is a way to refer data from many different arrays to one array, but without copying it. Example: import numpy as np a = np.array([2,3,4,5,6]) b = np.array([5,6,7,8]) c = np.ndarray([len(a)+len(b)]) offset = 0 c[offset:offset+len(a)] = a offset += len(a) c[offset:offset+len(b)] = b However, in the example above, c is a new array, so that if you modify some element of a or b , it is not modified in c at all. I would like that each index of c (i.e. c[0] , c[1] , etc