Windows IOT Memory leak
Getting a bad memory leak on a uwp c# app.
My app is growing continuously in memory size. also, IOTshell and DWM memory grows and it never released. even if the app is restarted. this continues until the device runs out of memory and crashes.
The app is running on windows iot core on rpi3b+ and uses primarily Nmodbus to get modbus data over serial on a usb to serial rs485 adapter.
//
public async Task FindSerial()
{
System.Diagnostics.Debug.WriteLine(DateTime.Now + "SetupSerial");
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(SerialDevice.GetDeviceSelector()); //get list of serial devices
int Count;
if (System.Diagnostics.Debugger.IsAttached) comportname = "CH340";
for (Count = 0; Count < devices.Count; Count++)
{
System.Diagnostics.Debug.WriteLine("Scanning Serial Devices..");
System.Diagnostics.Debug.WriteLine(devices[Count].Name);
if (devices[Count].Name.Contains(comportname))
{
System.Diagnostics.Debug.WriteLine("Found Matching Com Port");
break;
}
}
if (Count < devices.Count)
{
serial_deviceID = devices[Count].Id;
System.Diagnostics.Debug.WriteLine("UART Port: " + devices[Count].Name + ", " + devices[Count].Id);
}
}
public async Task GetData()
{
using (SerialDevice serialPort = await SerialDevice.FromIdAsync(serial_deviceID))
{
serialPort.BaudRate = 9600;
serialPort.DataBits = 8;
serialPort.Parity = SerialParity.None;
serialPort.StopBits = SerialStopBitCount.Two;
var factory = new ModbusFactory();
SerialDeviceAdapter adapter = new SerialDeviceAdapter(serialPort);
using (IModbusMaster Modbus_master = factory.CreateRtuMaster(adapter))
{
if (device_1_present == true)
{
if (device_1_type == device_types[0])
{
Device_1_Modbus_data_array = await Modbus_master.ReadInputRegistersAsync(device_1_address, dc_startAddress, dc_numRegisters);
}
else if (device_1_type == device_types[1])
{
Device_1_Modbus_data_array = await Modbus_master.ReadInputRegistersAsync(device_1_address, dc_startAddress, ac_numRegisters);
}
}
if (device_2_present == true)
{
Task.Delay(80).Wait();
if (device_2_type == device_types[0])
{
/// Task.Delay(50).Wait();
Device_2_Modbus_data_array = await Modbus_master.ReadInputRegistersAsync(device_2_address, ac_startAddress, dc_numRegisters);
}
else if (device_2_type == device_types[1])
{
Device_2_Modbus_data_array = await Modbus_master.ReadInputRegistersAsync(device_2_address, ac_startAddress, ac_numRegisters);
}
}
if (device_3_present == true)
{
Task.Delay(80).Wait();
if (device_3_type == device_types[0])
{
Device_3_Modbus_data_array = await Modbus_master.ReadInputRegistersAsync(device_3_address, aux_dc_startAddress, dc_numRegisters);
}
else if (device_3_type == device_types[1])
{
Device_3_Modbus_data_array = await Modbus_master.ReadInputRegistersAsync(device_3_address, aux_dc_startAddress, ac_numRegisters);
}
}
}
}
}