BUG: optimize: fix refcount errors in tnc

Fixes gh-3299
Merge pull request #3304 from pv/tnc-leak

BUG: optimize: fix refcount errors in tnc