soft-references

How are SoftReferences collected by JVMs in practice?

╄→гoц情女王★ 提交于 2020-01-29 04:24:27
问题 I have two separate caches running in a JVM (one controlled by a third party library) each using soft references. I would prefer for the JVM to clear out my controlled cache before the one controlled by the library. The SoftReference javadoc states: All soft references to softly-reachable objects are guaranteed to have been cleared before the virtual machine throws an OutOfMemoryError. Otherwise no constraints are placed upon the time at which a soft reference will be cleared or the order in

What is a softly reachable object?

杀马特。学长 韩版系。学妹 提交于 2020-01-04 05:50:47
问题 I am trying to study the meaning of a soft reference via this 'Soft References in Java' article: https://www.baeldung.com/java-soft-references My problem in understanding this article is that it defines the term "soft reference" via the term "softly reachable object", but I don't know what a "softly reachable object" means. That is, an object in the heap either has a reference to it or doesn't, right? A reference either points to a valid object or is null, right? When does an object become "

Can “soft references” exist in Python?

孤人 提交于 2019-12-21 04:12:19
问题 In other languages (e.g. Java), object references can be Strong, Weak, Soft or Phantom (http://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html). In Python, references are Strong by default and the WeakRef module allows weak references. Is it possible to have "soft references" in Python? In my particular case, I have a cache of objects that are time-consuming to create. Sometimes there may be no references to a cached object, but I don't want to throw the cached object

How to make the java system release Soft References?

帅比萌擦擦* 提交于 2019-12-17 15:55:28
问题 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

Soft reference does not behave as expected on Android

浪尽此生 提交于 2019-12-13 01:28:02
问题 I encountered a strange problem when I was using soft reference on Android. I implemented a class for bitmap cache, the source code is as follows: public class ImageCache { private static HashMap<String, SoftReference<Bitmap>> mCache = new HashMap<String, SoftReference<Bitmap>>(); private static final String TAG = "ImageCache"; public static Bitmap getBitmap(String url) { Bitmap bitmap = null; if (mCache.containsKey(url)) { Log.d(TAG, "use cache: " + url); bitmap = mCache.get(url).get(); if

Is there a way to FORCE weak and/or soft referenced objects to be GC'd in Java?

无人久伴 提交于 2019-12-12 08:22:33
问题 Here's my use case. We are trying to narrow down a potential memory leak in an application, and we are using a memory analysis tool to snapshot the heap so we can look for object instances and references. (In case it helps, we're using YourKit.) This application makes extensive use of dynamic and CGLIB proxies, which end up storing tons of references to classes and classloaders in WeakHashMaps. After our test case runs, we are expecting all hard references to object X and its classloader to

Rationale for Soft-/Weak-/PhantomReferences clearing references to objects which have reference to tracked object

徘徊边缘 提交于 2019-12-11 06:15:58
问题 The documentation for Soft-, Weak- and PhantomReferences all include a line simiar to the following (taken from PhantomReference ): At that time it will atomically clear all phantom references to that object and all phantom references to any other phantom-reachable objects from which that object is reachable. The part which is confusing me is the one about the other phantom-reachable objects. If I understand it correctly this describes this case: Objects: A B References: -> : Strong reference

Is there a SoftHashMap in Scala?

故事扮演 提交于 2019-12-10 13:09:59
问题 I'm aware of this question for java, but none of those implementations seem to play well with scala.collection.JavaConversions . I'm looking for something simple (e.g. single file, not a whole library ) that implements SoftHashMap such that it plays well with Scala Map (i.e. supports getOrElseUpdate , unzip , and the remaining Scala Map methods). 回答1: Implementation inspired by this java WeakHashMap: import scala.collection.mutable.{Map, HashMap} import scala.ref._ class SoftMap[K, V <:

Equivalent to SoftReference in .net?

青春壹個敷衍的年華 提交于 2019-12-07 05:42:14
问题 I am familiar with WeakReference , but I am looking for a reference type that is cleared only when memory is low, not simply every time when the gc runs (just like Java's SoftReference ). I'm looking for a way to implement a memory-sensitive cache. 回答1: No there isn't an equivalent. Is there a particular reason why WeakReference won't do the job? Here is a similar question to yours: Why doesn't .NET have a SoftReference as well as a WeakReference, like Java? 回答2: Maybe the ASP.NET Cache class

Soft (not: weak) references in C++ - Is it possible? Is there an implementation?

最后都变了- 提交于 2019-12-07 03:03:51
问题 In C++ I'm using boost::shared_ptr and boost::weak_ptr to automatically delete objects that are no longer needed. I know these work with reference counting. In Java, memory is managed by a garbage collector, which consideres the built-in object references as strong , WeakReference as weak and SoftReference as something in between (may be collected by the GC, but may as well survive the GC), which is really handy for caching objects for some time, but throwing them away as soon as free memory