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内存分析工具,
有什么建议来清理这个对象。
谢谢。