public delegate void SendCallbackType();
public class SenderBase
{
SenderBase()
{
mySend = new SendCallbackType(SendData);
mySend.BeginInvoke(SendCallback, null);
}
void SendData()
{
// process / sending data
}
void SendCallback(IAsyncResult ar)
{
**SendCallbackType worker = (SendCallbackType)((AsyncResult)ar).AsyncDelegate;
worker.EndInvoke(ar);**
//Above code is mandatory ? Working fine without them.
mySend.BeginInvoke(SendCallback, null);
}
// Test
Dictionary<SenderBase> SenderCollection = new Dictionary();
SenderCollection.Add(new SenderBase());
SenderCollection.Remove(0);
// Add and remove seven times
对象 (SenderBase) 不是垃圾收集的。他们不断地传给下一代。
使用 RedAnts 内存分析器,
清理对象的任何建议。
谢谢。