Added gc_handler to properly handle circular references. (#16703) closes #16703 Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>