You need to assign the returned object to a TaskInputHandlePtr smart pointer to prevent the object from being leaked. However, the object can be destroyed as soon as you have assigned it to the smart pointer. You can destroy the object by letting the smart pointer go out of scope.
Refer to C++ API: Why does my application have a memory leak after calling the Session::sendTaskInput() method? for more information.