我正在尝试 SharpSNMP 的新 9.0.0 RC1 版本的异步方法。它易于使用 - 实际上是旧同步方法的直接替代品。
我异步轮询 OID 列表的代码是:
// create a new get request message
var message = new GetRequestMessage(Messenger.NextRequestId, VersionCode.V2, SNMPReadCommunity, oids);
// get a new socket
using (Socket udpSocket = SNMPManager.GetSocket())
{
// wait for the response (this is async)
var res = await message.GetResponseAsync(SNMPManager, new UserRegistry(), udpSocket);
// check the variables we received
CheckSnmpResults(res.Pdu().Variables);
}
我将每个 get-request 的 OID 数量限制为 25。我的应用程序连接到 c.50 SNMP 设备。每隔 5 分钟,计时器会计时并在循环中多次运行上述代码,以便轮询每个设备上的 c.100 个 OID。都好。
问题是该message.GetResponseAsync
方法正在泄漏内存。每次轮询运行都会为我的应用程序的内存使用量增加 6 或 7 MB。使用 VS2015 内存分析器,我可以看到大量的OverlappedData对象,每个 65K,每次运行时数量都会增加message.GetResponseAsync
。因此,每 5 分钟运行一次以接收 c.200 SNMP get-requests 意味着我的应用程序的内存使用会迅速增加。
我是否以message.GetResponseAsync
某种方式使用不正确?这是 SharpSNMPLib 中的错误吗?
谢谢, 贾尔斯