靜態屬性返回帶有生成的模擬數據的列表。 在這個例子中,我從字符串創建IPAddress來模擬移動設備的IP。 內存泄漏的風險是什麼?靜態屬性與非靜態列表<T>
static readonly string[] IPv6Simu = { "fe80::3a6d:eeeb:8bff:4ef2", "fc01:abab:cdcd:efe0:49d2:473:579c:cfaa" };
static readonly string[] IPv4Simu = { "172.22.1.100", "172.22.1.100" };
static readonly string[] InterfaceName = { "mnet1", "mnet0" };
public static List<IpData> StaticSimulateIPFactory
{ get
{
List<IpData> simu = new List<IpData>();
try
{
IPAddress ip;
foreach (var IPv6 in IPv6Simu)
{
if (IPAddress.TryParse(IPv6, out ip))
{
simu.Add(new IpData() { InterfaceName = InterfaceName.FirstOrDefault(), IPAddress = ip });
}
}
foreach (var IPv4 in IPv4Simu)
{
if (IPAddress.TryParse(IPv4, out ip))
{
simu.Add(new IpData() { InterfaceName = InterfaceName.FirstOrDefault(), IPAddress = ip });
}
}
return simu;
}
catch (Exception)
{
simu.Add(new IpData() { InterfaceName = "INV", IPAddress = new IPAddress(new byte[]{127,0,0,1})});
return simu;
}
}
}
你在哪裏*期待*內存泄漏?如果你知道這一點,你就知道該怎麼處理以防止這些。 – HimBromBeere