I have a memory leak when using ConcurrentQueue :
requestObject request = xxx; Item obj= new Item (); obj.MessageReceived += obj_MessageReceived; obj.Exited += obj_Exited; request.Key = obj.Key; obj.AddRequest(request); _queue.TryAdd(obj.Key, obj);
In the Exit callback, I delete the resource:
void LiveSphere_Exited(string key) { Item instance; _queue.TryRemove(key, out instance); Task.Factory.StartNew(() => { var wait = new SpinWait(); while (instance.MessageCount > 0) { wait.SpinOnce(); } }) .ContinueWith((t) => { if (instance != null) { //Cleanup resources instance.MessageReceived -= obj_MessageReceived; instance.Exited -= obj_Exited; instance.Dispose(); instance = null; } }); }
When I look at the code, I still have an βItemβ object associated with the root, but I donβt know where I can dispose ..., The exited method is launched, and _queue removes the βItemβ object from the queue.
When I read the documentation, concurrentqueue copies the link to the queue.
Can you help me find out where the memory leak is?
dnx
source share