From e5be822032ca41caba4aa1642350c6082e265773 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 27 Nov 2018 12:06:04 +0100 Subject: [PATCH] - .NET API: DataSet implements IDisposable interface, Report/DataSet GetValues methods return now clones of the original native values to prevent GC issues --- dotnet/IEC61850forCSharp/DataSet.cs | 16 +++++++++++++--- dotnet/IEC61850forCSharp/ReportControlBlock.cs | 2 ++ dotnet/IEC61850forCSharp/Reporting.cs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dotnet/IEC61850forCSharp/DataSet.cs b/dotnet/IEC61850forCSharp/DataSet.cs index c0c887e9..4a1e0fb0 100644 --- a/dotnet/IEC61850forCSharp/DataSet.cs +++ b/dotnet/IEC61850forCSharp/DataSet.cs @@ -1,7 +1,7 @@ /* * DataSet.cs * - * Copyright 2014 Michael Zillgith + * Copyright 2014-2018 Michael Zillgith * * 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 /// of a data set. /// - public class DataSet + public class DataSet : IDisposable { [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern void ClientDataSet_destroy (IntPtr self); @@ -91,7 +91,7 @@ namespace IEC61850 values = new MmsValue (nativeValues, false); } - return values; + return values.Clone(); } @@ -106,6 +106,16 @@ namespace IEC61850 return ClientDataSet_getDataSetSize (nativeObject); } + public void Dispose() + { + lock (this) { + if (nativeObject != IntPtr.Zero) { + ClientDataSet_destroy (nativeObject); + nativeObject = IntPtr.Zero; + } + } + } + ~DataSet () { ClientDataSet_destroy (nativeObject); diff --git a/dotnet/IEC61850forCSharp/ReportControlBlock.cs b/dotnet/IEC61850forCSharp/ReportControlBlock.cs index 9e6daecf..1854480f 100644 --- a/dotnet/IEC61850forCSharp/ReportControlBlock.cs +++ b/dotnet/IEC61850forCSharp/ReportControlBlock.cs @@ -34,6 +34,8 @@ namespace IEC61850 /// /// Report handler. /// + /// represents the received report. DON'T use this object + /// outside the scope of the report handler! public delegate void ReportHandler (Report report, object parameter); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/dotnet/IEC61850forCSharp/Reporting.cs b/dotnet/IEC61850forCSharp/Reporting.cs index 398db95a..8b72f089 100644 --- a/dotnet/IEC61850forCSharp/Reporting.cs +++ b/dotnet/IEC61850forCSharp/Reporting.cs @@ -293,7 +293,7 @@ namespace IEC61850 values = new MmsValue(dataSetValues); } - return values; + return values.Clone(); } ///