I am seeing a weird behaviour when using the c# gemfire client. I am seeing memory leak on both the key and value when putting them into the region.
After further investigation, i note that the GCHandle created in the SafeM2UMConvert() is not properly released. However amazingly, when i set both the value and key to null (note the commented line), both the key and value are correctly garbage-collected. Wonder if anyone can provide a explanation of this behaviour?
** i would think that both key and value will be removed upon gc, which isn't the case either. I tried to call gc.collect after put but it does not help.
Here is a bit on the implementation,
function Add()
{
lock(sync)
{
var key = new Key();
var value = new Value(key);
Region.Put(key, value);
//key = null;
//value = null; these 2 lines did the magic
}
[Serializable]
public class Key: IEquatable<Key>, IGFSerializable
[Serializable]
public class Value : IGFSerializable, IEquatable<Value>
Here is a bit of the call stack where the handler is created (i used the .net momory profiler to obtain this),
mscorlib!System.Runtime.InteropServices.GCHandle..ctor( object,GCHandleType )
mscorlib!System.Runtime.InteropServices.GCHandle.Alloc( object )
GemStone.GemFire.Cache!<Module>.gemfire.ManagedCacheableKey.{ctor}( ManagedCacheableKey*,IGFSerializable )
GemStone.GemFire.Cache!<Module>.GemStone.GemFire.Cache.?A0xa28d4856.SafeM2UMConvert<struct GemStone::GemFire::Cache::IGFSerializable,class gemfire::ManagedCacheableKey,class gemfire::Serializable,class GemStone::GemFire::Cache::Serializable>( IGFSerializable )
GemStone.GemFire.Cache!GemStone.GemFire.Cache.Region.Put( ICacheableKey,IGFSerializable,IGFSerializable )
GemStone.GemFire.Cache!GemStone.GemFire.Cache.Region.Put( ICacheableKey,IGFSerializable )
Add()