title: How to cause soft references to be cleared in Java?
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Is there any way to get Java to more eagerly clear up the soft references?</p>
  
  <hr>
  
  <p><strong>Found <a href="https://stackoverflow.com/questions/299659/what-is-the-difference-between-a-soft-reference-and-a-weak-reference-in-java">here</a></strong>: </p>
  
  <blockquote>
    <p>"It is guaranteed though that all
    SoftReferences will get cleared before
    OutOfMemoryError is thrown, so they
    theoretically can't cause an OOME."</p>
  </blockquote>
  
  <p>So does this mean that the above scenario MUST mean I have a memory leak somewhere with some class holding a hard reference on my cached object?</p>