Apache Ignite goes OOM while using Eviction Policy
<p>I'm trying cache data with Apache Ignite 1.6 using an LruEvictionPolicy. I wrote some test code to observe caching behaviors (for Apache Ignite / Redis / Memcached / .NET in process caching). I'm working with Win10 / VS2015.</p>

<pre><code>static void Main(string[] args)
    {

        // 64Bit -&gt; size in memory for an atring = 26 + length * 2
        // using 512KB string
        StringBuilder builder = new StringBuilder(262131);
        for (int i = 0; i &lt; 262131; i++)
        {
            builder.Append('G');
        }

        ICache cache;
        IList&lt;bool&gt; cacheMemTest;

        cache = new IgniteCache();
        cacheMemTest = TestCache(cache, builder.ToString(), 10);
        DrawResult(GetFilestreamForName("IgniteCache"), cacheMemTest);
    }

    private static IList&lt;bool&gt; TestCache(ICache cache, string testValue, int delay)
    {
        int numOfElements = 10000;
        for (int i = 0; i &lt; numOfElements; i++)
        {
            var currentString = String.Copy(testValue);
            cache.AddValue(i.ToString(), currentString);
            currentString = null;
            GC.Collect();
        }

        IList&lt;bool&gt; boolList = new List&lt;bool&gt;(numOfElements);
        for (int i = 0; i &lt; numOfElements; i++)
        {
            boolList.Add(cache.HasElement(i.ToString()));
        }

        return boolList;
    }
</code></pre>

<p>The IgniteCach class looks like this:</p>

<pre><code>class IgniteCache : ICache, IDisposable
{

    private IIgnite _ignite;
    private Apache.Ignite.Core.Cache.ICache&lt;string, string&gt; _cache;

    public IgniteCache()
    {
        var conf = new IgniteConfiguration();
        //conf.JvmInitialMemoryMb = 512;
        //conf.JvmMaxMemoryMb = 1024;

        conf.JvmOptions = new string[] { "-XX:+UseParNewGC",
    "-XX:+UseConcMarkSweepGC",
    "-XX:+UseTLAB",
    "-XX:NewSize=128m",
    "-XX:MaxNewSize=128m",
    "-XX:MaxTenuringThreshold=0",
    "-XX:SurvivorRatio=1024",
    "-XX:+UseCMSInitiatingOccupancyOnly",
    "-XX:CMSInitiatingOccupancyFraction=60" };

        var cacheConf = new CacheConfiguration();
        cacheConf.CopyOnRead = false;
        cacheConf.EagerTtl = false;
        cacheConf.AtomicityMode = CacheAtomicityMode.Atomic;
        cacheConf.WriteBehindEnabled = false;
        cacheConf.EvictionPolicy = new Apache.Ignite.Core.Cache.Eviction.LruEvictionPolicy()
        {
            MaxMemorySize = 1073741824
        };

        cacheConf.Name = "cache";
        cacheConf.CacheMode = CacheMode.Local;
        cacheConf.Backups = 0;
        cacheConf.OffHeapMaxMemory = -1;
        cacheConf.EnableSwap = false;
        conf.CacheConfiguration = new List&lt;CacheConfiguration&gt;() { cacheConf };
        conf.DiscoverySpi = new TcpDiscoverySpi
        {
            IpFinder = new TcpDiscoveryStaticIpFinder
            {
                Endpoints = new[] { "127.0.0.1:47500" }
            },
            SocketTimeout = TimeSpan.FromSeconds(0.3)
        };

        _ignite = Ignition.Start(conf);
        TimeSpan timeSpan = new TimeSpan(6, 0, 0);
        _cache = _ignite.GetCache&lt;string, string&gt;("cache").WithExpiryPolicy(new Apache.Ignite.Core.Cache.Expiry.ExpiryPolicy(timeSpan, timeSpan, timeSpan));
    }

    public void AddValue(string key, string values)
    {
        _cache.Put(key, values);
    }

    public void Dispose()
    {
        _ignite.Dispose();
    }

    public string GetValue(string key)
    {
        if (HasElement(key))
        {
            return _cache.Get(key);
        }
        return null;
    }

    public bool HasElement(string key)
    {
        return _cache.ContainsKey(key);
    }
}
</code></pre>

<p>When using and "conf.JvmMaxMemoryMb = 1024;" I will run out of memory, the LruEvictionPolicy seems to do nothing. Removing the JVM max. memory restriction the program will run until the end while allocating ~5GB. Now I'm checking the result: about 2/5 of the cached data is still in the cache. Thats my wanted/expected behavior but with way too much memory used.</p>

<p>Is there a way to reduce the used memory?</p>