Fix dangling model pointer after reference cleanup (Fixes #1653)