[Java] Fix memory management issues in Flight example (#219)