diff --git a/src/TensorFlowNET.Core/Tensors/AllocationType.cs b/src/TensorFlowNET.Core/Tensors/AllocationType.cs
deleted file mode 100644
index 9f5c8bad..00000000
--- a/src/TensorFlowNET.Core/Tensors/AllocationType.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-namespace Tensorflow
-{
- ///
- /// Used internally to
- ///
- public enum AllocationType
- {
- None = 0,
- ///
- /// Allocation was done by passing in a pointer, might be also holding reference to a C# object.
- ///
- FromPointer = 1,
- ///
- /// Allocation was done by calling c_api.TF_AllocateTensor or TF decided it has to copy data during c_api.TF_NewTensor.
- /// Deallocation is handled solely by Tensorflow.
- ///
- Tensorflow = 2,
- ///
- /// Allocation was done by Marshal.AllocateHGlobal
- ///
- Marshal = 3,
- ///
- /// Allocation was done by GCHandle.Alloc
- ///
- GCHandle = 4,
- }
-}
\ No newline at end of file
diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs
index 3289c938..3cfcb7d0 100644
--- a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs
+++ b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs
@@ -19,8 +19,6 @@ using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
using System.Text;
using static Tensorflow.c_api;
@@ -29,21 +27,6 @@ namespace Tensorflow
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
public partial class Tensor
{
- ///
- /// The handle that was used to allocate this tensor, dependent on .
- ///
- protected object AllocationHandle;
-
- ///
- /// True if this Tensor holds data allocated by C#.
- ///
- public bool IsMemoryOwner => AllocationType >= AllocationType.Marshal;
-
- ///
- /// The allocation method used to create this Tensor.
- ///
- public AllocationType AllocationType { get; protected set; }
-
public IntPtr TensorDataPointer => _handle == IntPtr.Zero ? IntPtr.Zero : TF_TensorData(_handle);
public Tensor()
@@ -125,11 +108,7 @@ namespace Tensorflow
/// Size of the tensor in memory
public Tensor(IntPtr data_ptr, long[] shape, TF_DataType dType, int num_bytes)
{
- unsafe
- {
- _handle = TF_NewTensor(dType, dims: shape, num_dims: shape.Length, data: data_ptr, len: (ulong)num_bytes);
- AllocationType = TF_TensorData(_handle) == data_ptr ? AllocationType.FromPointer : AllocationType.Tensorflow;
- }
+ _handle = TF_NewTensor(dType, dims: shape, num_dims: shape.Length, data: data_ptr, len: (ulong)num_bytes);
}
public unsafe Tensor(NDArray nd)
diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.cs b/src/TensorFlowNET.Core/Tensors/Tensor.cs
index d1a133df..05655f92 100644
--- a/src/TensorFlowNET.Core/Tensors/Tensor.cs
+++ b/src/TensorFlowNET.Core/Tensors/Tensor.cs
@@ -93,7 +93,8 @@ namespace Tensorflow
/// TFE_TensorHandle
///
public SafeTensorHandleHandle EagerTensorHandle { get; set; }
-
+ protected bool _createdInGraphMode;
+ public bool CreatedInGraphMode => _createdInGraphMode;
public bool IsEagerTensor => this is EagerTensor;
public bool IsSparseTensor => this is SparseTensor;
@@ -262,29 +263,6 @@ namespace Tensorflow
#if TRACK_TENSOR_LIFE
print($"Delete Tensor 0x{handle.ToString("x16")} {AllocationType} Data: 0x{TensorDataPointer.ToString("x16")}");
#endif
- if (AllocationHandle != null)
- {
- if (AllocationType == AllocationType.GCHandle)
- {
- ((GCHandle)AllocationHandle).Free();
- AllocationHandle = null;
- AllocationType = AllocationType.None;
- }
- else if (AllocationType == AllocationType.Marshal)
- {
- Marshal.FreeHGlobal((IntPtr)AllocationHandle);
- AllocationHandle = null;
- AllocationType = AllocationType.None;
- }
- else if (AllocationType == AllocationType.FromPointer)
- {
- AllocationHandle = null;
- AllocationType = AllocationType.None;
- }
- else
- throw new InvalidOperationException($"Tensor.AllocationHandle is not null ({AllocationHandle}) but AllocationType is not matched to a C# allocation type ({AllocationType}).");
- }
-
if (dtype == TF_DataType.TF_STRING)
{
long size = 1;