BUG: optimize: fix refcount errors in tnc

Fixes gh-3299