- .NET API: DataSet implements IDisposable interface, Report/DataSet GetValues methods return now clones of the original native values to prevent GC issues

pull/93/head
Michael Zillgith 7 years ago
parent 4ba6d9903d
commit e5be822032

@ -1,7 +1,7 @@
/* /*
* DataSet.cs * DataSet.cs
* *
* Copyright 2014 Michael Zillgith * Copyright 2014-2018 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -34,7 +34,7 @@ namespace IEC61850
/// This class is used to represent a data set. It is used to store the values /// This class is used to represent a data set. It is used to store the values
/// of a data set. /// of a data set.
/// </summary> /// </summary>
public class DataSet public class DataSet : IDisposable
{ {
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void ClientDataSet_destroy (IntPtr self); static extern void ClientDataSet_destroy (IntPtr self);
@ -91,7 +91,7 @@ namespace IEC61850
values = new MmsValue (nativeValues, false); values = new MmsValue (nativeValues, false);
} }
return values; return values.Clone();
} }
@ -106,6 +106,16 @@ namespace IEC61850
return ClientDataSet_getDataSetSize (nativeObject); return ClientDataSet_getDataSetSize (nativeObject);
} }
public void Dispose()
{
lock (this) {
if (nativeObject != IntPtr.Zero) {
ClientDataSet_destroy (nativeObject);
nativeObject = IntPtr.Zero;
}
}
}
~DataSet () ~DataSet ()
{ {
ClientDataSet_destroy (nativeObject); ClientDataSet_destroy (nativeObject);

@ -34,6 +34,8 @@ namespace IEC61850
/// <summary> /// <summary>
/// Report handler. /// Report handler.
/// </summary> /// </summary>
/// <param name="report">represents the received report. DON'T use this object
/// outside the scope of the report handler!</param>
public delegate void ReportHandler (Report report, object parameter); public delegate void ReportHandler (Report report, object parameter);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]

@ -293,7 +293,7 @@ namespace IEC61850
values = new MmsValue(dataSetValues); values = new MmsValue(dataSetValues);
} }
return values; return values.Clone();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save