/*
-* Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
/// Creates a TensorsData instance with handle which is given by TensorsInfo.
/// </summary>
/// <param name="handle">The handle of tensors data.</param>
- /// <param name="info">The handle of tensors info. (Default: null)</param>
+ /// <param name="info">The handle of tensors info.</param>
/// <param name="isFetch">The boolean value for fetching the data (Default: false)</param>
+ /// <param name="hasOwnership">The boolean value for automatic disposal (Default: true)</param>
/// <since_tizen> 6 </since_tizen>
- private TensorsData(IntPtr handle, TensorsInfo info, bool isFetch)
+ private TensorsData(IntPtr handle, TensorsInfo info, bool isFetch = false, bool hasOwnership = true)
{
NNStreamer.CheckNNStreamerSupport();
NNStreamerError ret = NNStreamerError.None;
/* Set internal object */
_handle = handle;
- _tensorsInfo = info;
+ /* Because developers can change the TensorsInfo object, it should be stored as a deep-copied instance. */
+ _tensorsInfo = info.Clone();
/* Set count */
int count = 0;
- ret = Interop.Util.GetTensorsCount(_handle, out count);
+ ret = Interop.Util.GetTensorsCount(_tensorsInfo.GetTensorsInfoHandle(), out count);
NNStreamer.CheckException(ret, "unable to get the count of TensorsData");
_dataList = new ArrayList(count);
_dataList.Add(bufData);
}
}
+
+ /* If it created as DataReceivedEventArgs, do not dispose. */
+ _disposed = !hasOwnership;
}
/// <summary>
if (disposing)
{
// release managed object
+ _tensorsInfo.Dispose();
+ _tensorsInfo = null;
}
// release unmanaged objects
}
}
- internal static TensorsData CreateFromNativeHandle(IntPtr dataHandle, IntPtr infoHandle, bool isFetch)
+ internal static TensorsData CreateFromNativeHandle(IntPtr dataHandle, IntPtr infoHandle, bool isFetch = false, bool hasOwnership = true)
{
- TensorsData retTensorsData = null;
+ TensorsInfo info = null;
- if (infoHandle == IntPtr.Zero)
- {
- retTensorsData = new TensorsData(dataHandle, null, isFetch);
- }
- else
+ if (infoHandle != IntPtr.Zero)
{
- TensorsInfo info = TensorsInfo.ConvertTensorsInfoFromHandle(infoHandle);
- retTensorsData = new TensorsData(dataHandle, info, isFetch);
+ info = TensorsInfo.ConvertTensorsInfoFromHandle(infoHandle);
}
- return retTensorsData;
+ return new TensorsData(dataHandle, info, isFetch, hasOwnership);
}
private void CheckIndex(int index)