I expect that your clean up code calls FreeMem rather than Dispose on the pointer. That's the only thing I can imagine that has those symptoms. FreeMem just frees the memory, but Dispose will also finalize the contents before freeing.
When you call Dispose you must supply a correctly typed pointer. For your case you must pass a TestPointer to Dispose.