title: How to calculate sizeof for Lrucache?
body: <p>I have a data structure, like this:</p>
  
  <pre><code>public class Data{
    private String charData;
    private int intData;
  
    //get-set methods here
  }
  </code></pre>
  
  <p>Now, I want to create a lru cache and I need to override sizeof...as each char in java occupies 2bytes, while an int is 4 bytes I though making:</p>
  
  <pre><code>cachedData= new LruCache&lt;String,Data&gt;(CACHE_MB*1024*1024){
      protected int sizeOf(String k,Data v){ 
                   return 4 +2*v.getCharData().length();
   }
  </code></pre>
  
  <p>but Strings are objects, so I think they take more than just memory for characters, moreover Data is an object too so I'm not sure my method is correct.</p>
  
  <p>By the way what happens if I reach maximum cache size with a wrong sizeOf method?</p>