Prevent input tensors from being GC'ed before PInvoke occurs (#335)
Prevent input tensors from being GC'ed before PInvoke occurs (#335)

We were seeing test failures because GC would occur after tensor handles were copied
to IntPtr array but before PInvoke finished.  GC would run the finalizer, which freed
the native tensors, while TF was still running.

Prevent the GC from finalizing these by telling it we're still using the managed object.

There may be more instances of this problem with other types.  The generic pattern to search for
is a manged object with a finalizer that exposes its native state (like TFDisposable), and that native
state is used after the last reference to the managed object in the method and no external
reference is guaranteed.
migueldeicaza/TensorFlowSharp,migueldeicaza/TensorFlowSharp,migueldeicaza/TensorFlowSharp