BUG: optimize: fix refcount errors in tnc
BUG: optimize: fix refcount errors in tnc

Fixes gh-3299

mhogg/scipy,niknow/scipy,nonhermitian/scipy,jakevdp/scipy,minhlongdo/scipy,sonnyhu/scipy,gdooper/scipy,mortonjt/scipy,befelix/scipy,larsmans/scipy,efiring/scipy,Newman101/scipy,gef756/scipy,sauliusl/scipy,sriki18/scipy,rmcgibbo/scipy,WarrenWeckesser/scipy,surhudm/scipy,WillieMaddox/scipy,andyfaff/scipy,niknow/scipy,argriffing/scipy,andim/scipy,ilayn/scipy,haudren/scipy,arokem/scipy,cpaulik/scipy,pbrod/scipy,gfyoung/scipy,apbard/scipy,Dapid/scipy,minhlongdo/scipy,zaxliu/scipy,mhogg/scipy,sauliusl/scipy,vanpact/scipy,maciejkula/scipy,lukauskas/scipy,sriki18/scipy,befelix/scipy,ogrisel/scipy,jseabold/scipy,behzadnouri/scipy,pyramania/scipy,minhlongdo/scipy,Stefan-Endres/scipy,Srisai85/scipy,WillieMaddox/scipy,arokem/scipy,aeklant/scipy,maciejkula/scipy,WarrenWeckesser/scipy,jonycgn/scipy,niknow/scipy,nvoron23/scipy,mortada/scipy,lukauskas/scipy,zaxliu/scipy,person142/scipy,dominicelse/scipy,Newman101/scipy,mtrbean/scipy,witcxc/scipy,aarchiba/scipy,endolith/scipy,mdhaber/scipy,rmcgibbo/scipy,mortada/scipy,person142/scipy,aeklant/scipy,andyfaff/scipy,petebachant/scipy,argriffing/scipy,anntzer/scipy,lhilt/scipy,rgommers/scipy,zaxliu/scipy,zxsted/scipy,FRidh/scipy,jseabold/scipy,lukauskas/scipy,vigna/scipy,aarchiba/scipy,tylerjereddy/scipy,richardotis/scipy,ilayn/scipy,mdhaber/scipy,gdooper/scipy,fredrikw/scipy,gertingold/scipy,person142/scipy,WarrenWeckesser/scipy,trankmichael/scipy,Dapid/scipy,pizzathief/scipy,anntzer/scipy,dominicelse/scipy,richardotis/scipy,felipebetancur/scipy,jseabold/scipy,cpaulik/scipy,mgaitan/scipy,apbard/scipy,kalvdans/scipy,mikebenfield/scipy,ales-erjavec/scipy,mortonjt/scipy,pbrod/scipy,vberaudi/scipy,sonnyhu/scipy,gef756/scipy,ilayn/scipy,kalvdans/scipy,pbrod/scipy,vigna/scipy,Shaswat27/scipy,jor-/scipy,behzadnouri/scipy,niknow/scipy,maniteja123/scipy,matthewalbani/scipy,lukauskas/scipy,nmayorov/scipy,endolith/scipy,vberaudi/scipy,dominicelse/scipy,pschella/scipy,newemailjdm/scipy,njwilson23/scipy,tylerjereddy/scipy,scipy/scipy,ortylp/scipy,anielsen001/scipy,newemailjdm/scipy,perimosocordiae/scipy,jamestwebber/scipy,Gillu13/scipy,argriffing/scipy,dominicelse/scipy,rmcgibbo/scipy,gfyoung/scipy,endolith/scipy,pschella/scipy,gef756/scipy,ChanderG/scipy,befelix/scipy,FRidh/scipy,jjhelmus/scipy,WarrenWeckesser/scipy,anielsen001/scipy,mingwpy/scipy,maniteja123/scipy,woodscn/scipy,bkendzior/scipy,petebachant/scipy,Gillu13/scipy,vigna/scipy,nvoron23/scipy,petebachant/scipy,WillieMaddox/scipy,ndchorley/scipy,rgommers/scipy,fredrikw/scipy,woodscn/scipy,raoulbq/scipy,scipy/scipy,larsmans/scipy,pschella/scipy,matthewalbani/scipy,Stefan-Endres/scipy,pbrod/scipy,giorgiop/scipy,Kamp9/scipy,Stefan-Endres/scipy,mhogg/scipy,josephcslater/scipy,lhilt/scipy,jsilter/scipy,andyfaff/scipy,surhudm/scipy,anielsen001/scipy,Kamp9/scipy,jjhelmus/scipy,njwilson23/scipy,minhlongdo/scipy,gdooper/scipy,rmcgibbo/scipy,woodscn/scipy,zaxliu/scipy,mortonjt/scipy,sonnyhu/scipy,fredrikw/scipy,josephcslater/scipy,maniteja123/scipy,jamestwebber/scipy,ortylp/scipy,piyush0609/scipy,trankmichael/scipy,giorgiop/scipy,futurulus/scipy,pnedunuri/scipy,vhaasteren/scipy,felipebetancur/scipy,ChanderG/scipy,vigna/scipy,petebachant/scipy,giorgiop/scipy,apbard/scipy,pnedunuri/scipy,ortylp/scipy,arokem/scipy,vhaasteren/scipy,Shaswat27/scipy,jakevdp/scipy,mgaitan/scipy,jjhelmus/scipy,mhogg/scipy,vanpact/scipy,jsilter/scipy,giorgiop/scipy,jakevdp/scipy,mortonjt/scipy,pschella/scipy,fernand/scipy,kleskjr/scipy,kleskjr/scipy,Newman101/scipy,maciejkula/scipy,dch312/scipy,Eric89GXL/scipy,Kamp9/scipy,chatcannon/scipy,aman-iitj/scipy,mtrbean/scipy,ChanderG/scipy,Dapid/scipy,piyush0609/scipy,piyush0609/scipy,pnedunuri/scipy,larsmans/scipy,grlee77/scipy,matthew-brett/scipy,mikebenfield/scipy,perimosocordiae/scipy,haudren/scipy,ogrisel/scipy,mingwpy/scipy,mtrbean/scipy,e-q/scipy,giorgiop/scipy,grlee77/scipy,petebachant/scipy,Eric89GXL/scipy,felipebetancur/scipy,pyramania/scipy,matthew-brett/scipy,jor-/scipy,jseabold/scipy,apbard/scipy,scipy/scipy,niknow/scipy,nonhermitian/scipy,efiring/scipy,mortada/scipy,ndchorley/scipy,mdhaber/scipy,ilayn/scipy,Gillu13/scipy,andim/scipy,andim/scipy,mgaitan/scipy,chatcannon/scipy,grlee77/scipy,sauliusl/scipy,mingwpy/scipy,arokem/scipy,niknow/scipy,matthew-brett/scipy,zerothi/scipy,mortada/scipy,vanpact/scipy,pizzathief/scipy,Gillu13/scipy,dch312/scipy,fernand/scipy,njwilson23/scipy,newemailjdm/scipy,Stefan-Endres/scipy,ndchorley/scipy,matthewalbani/scipy,surhudm/scipy,ales-erjavec/scipy,surhudm/scipy,anntzer/scipy,futurulus/scipy,pizzathief/scipy,ilayn/scipy,chatcannon/scipy,anntzer/scipy,aman-iitj/scipy,mikebenfield/scipy,argriffing/scipy,anielsen001/scipy,nmayorov/scipy,hainm/scipy,andim/scipy,gertingold/scipy,trankmichael/scipy,vberaudi/scipy,behzadnouri/scipy,jsilter/scipy,aeklant/scipy,haudren/scipy,zxsted/scipy,zerothi/scipy,FRidh/scipy,ogrisel/scipy,ortylp/scipy,aman-iitj/scipy,matthew-brett/scipy,dch312/scipy,witcxc/scipy,grlee77/scipy,jamestwebber/scipy,jakevdp/scipy,aman-iitj/scipy,njwilson23/scipy,pizzathief/scipy,mdhaber/scipy,surhudm/scipy,argriffing/scipy,efiring/scipy,fernand/scipy,Shaswat27/scipy,vhaasteren/scipy,ndchorley/scipy,josephcslater/scipy,Dapid/scipy,larsmans/scipy,kalvdans/scipy,aman-iitj/scipy,jonycgn/scipy,woodscn/scipy,arokem/scipy,hainm/scipy,futurulus/scipy,bkendzior/scipy,lhilt/scipy,Kamp9/scipy,e-q/scipy,gfyoung/scipy,woodscn/scipy,woodscn/scipy,jakevdp/scipy,cpaulik/scipy,gertingold/scipy,newemailjdm/scipy,ndchorley/scipy,nvoron23/scipy,haudren/scipy,Newman101/scipy,Eric89GXL/scipy,cpaulik/scipy,gdooper/scipy,tylerjereddy/scipy,zerothi/scipy,Eric89GXL/scipy,Shaswat27/scipy,ales-erjavec/scipy,hainm/scipy,WillieMaddox/scipy,sriki18/scipy,pizzathief/scipy,nvoron23/scipy,gef756/scipy,pnedunuri/scipy,fredrikw/scipy,jonycgn/scipy,anielsen001/scipy,minhlongdo/scipy,vhaasteren/scipy,jseabold/scipy,Shaswat27/scipy,argriffing/scipy,rgommers/scipy,mgaitan/scipy,sauliusl/scipy,hainm/scipy,Srisai85/scipy,maciejkula/scipy,perimosocordiae/scipy,petebachant/scipy,befelix/scipy,mgaitan/scipy,perimosocordiae/scipy,vberaudi/scipy,mdhaber/scipy,jonycgn/scipy,jonycgn/scipy,WillieMaddox/scipy,Stefan-Endres/scipy,mhogg/scipy,nmayorov/scipy,jjhelmus/scipy,sauliusl/scipy,sonnyhu/scipy,piyush0609/scipy,vanpact/scipy,futurulus/scipy,pyramania/scipy,mikebenfield/scipy,gef756/scipy,grlee77/scipy,futurulus/scipy,FRidh/scipy,trankmichael/scipy,raoulbq/scipy,Srisai85/scipy,gfyoung/scipy,lhilt/scipy,tylerjereddy/scipy,rgommers/scipy,aeklant/scipy,njwilson23/scipy,hainm/scipy,newemailjdm/scipy,ogrisel/scipy,cpaulik/scipy,WarrenWeckesser/scipy,anntzer/scipy,raoulbq/scipy,mhogg/scipy,sriki18/scipy,mortonjt/scipy,jsilter/scipy,ChanderG/scipy,richardotis/scipy,vanpact/scipy,gef756/scipy,vberaudi/scipy,vhaasteren/scipy,Gillu13/scipy,matthewalbani/scipy,jsilter/scipy,endolith/scipy,pyramania/scipy,nonhermitian/scipy,lhilt/scipy,fernand/scipy,Shaswat27/scipy,richardotis/scipy,chatcannon/scipy,aarchiba/scipy,Stefan-Endres/scipy,rmcgibbo/scipy,jseabold/scipy,sriki18/scipy,dominicelse/scipy,ogrisel/scipy,behzadnouri/scipy,felipebetancur/scipy,newemailjdm/scipy,pyramania/scipy,larsmans/scipy,jamestwebber/scipy,ilayn/scipy,josephcslater/scipy,dch312/scipy,mingwpy/scipy,mtrbean/scipy,andyfaff/scipy,mdhaber/scipy,e-q/scipy,maniteja123/scipy,andim/scipy,nvoron23/scipy,sauliusl/scipy,nmayorov/scipy,jor-/scipy,zaxliu/scipy,zerothi/scipy,jonycgn/scipy,raoulbq/scipy,zxsted/scipy,scipy/scipy,ales-erjavec/scipy,futurulus/scipy,aarchiba/scipy,aarchiba/scipy,e-q/scipy,pnedunuri/scipy,witcxc/scipy,piyush0609/scipy,fredrikw/scipy,scipy/scipy,ortylp/scipy,ChanderG/scipy,felipebetancur/scipy,hainm/scipy,sriki18/scipy,tylerjereddy/scipy,nonhermitian/scipy,josephcslater/scipy,gertingold/scipy,ales-erjavec/scipy,kleskjr/scipy,person142/scipy,kalvdans/scipy,fernand/scipy,sonnyhu/scipy,felipebetancur/scipy,aman-iitj/scipy,Dapid/scipy,Eric89GXL/scipy,richardotis/scipy,perimosocordiae/scipy,zxsted/scipy,mgaitan/scipy,apbard/scipy,haudren/scipy,dch312/scipy,perimosocordiae/scipy,larsmans/scipy,nvoron23/scipy,aeklant/scipy,ales-erjavec/scipy,kleskjr/scipy,endolith/scipy,surhudm/scipy,nmayorov/scipy,befelix/scipy,vigna/scipy,Newman101/scipy,mtrbean/scipy,trankmichael/scipy,vanpact/scipy,pbrod/scipy,trankmichael/scipy,rgommers/scipy,Eric89GXL/scipy,cpaulik/scipy,anielsen001/scipy,fernand/scipy,ChanderG/scipy,bkendzior/scipy,mikebenfield/scipy,gertingold/scipy,mortada/scipy,mortonjt/scipy,matthewalbani/scipy,mingwpy/scipy,jjhelmus/scipy,witcxc/scipy,chatcannon/scipy,lukauskas/scipy,witcxc/scipy,raoulbq/scipy,zerothi/scipy,anntzer/scipy,mortada/scipy,minhlongdo/scipy,zxsted/scipy,Gillu13/scipy,behzadnouri/scipy,WillieMaddox/scipy,kalvdans/scipy,FRidh/scipy,haudren/scipy,Dapid/scipy,WarrenWeckesser/scipy,zerothi/scipy,andyfaff/scipy,chatcannon/scipy,pschella/scipy,bkendzior/scipy,bkendzior/scipy,jamestwebber/scipy,andim/scipy,jor-/scipy,andyfaff/scipy,Kamp9/scipy,mingwpy/scipy,vberaudi/scipy,matthew-brett/scipy,kleskjr/scipy,zxsted/scipy,Newman101/scipy,vhaasteren/scipy,endolith/scipy,person142/scipy,pnedunuri/scipy,gfyoung/scipy,maniteja123/scipy,Kamp9/scipy,ndchorley/scipy,efiring/scipy,jor-/scipy,Srisai85/scipy,maniteja123/scipy,sonnyhu/scipy,e-q/scipy,FRidh/scipy,raoulbq/scipy,njwilson23/scipy,scipy/scipy,pbrod/scipy,zaxliu/scipy,rmcgibbo/scipy,richardotis/scipy,nonhermitian/scipy,kleskjr/scipy,Srisai85/scipy,mtrbean/scipy,gdooper/scipy,Srisai85/scipy,fredrikw/scipy,giorgiop/scipy,maciejkula/scipy,efiring/scipy,lukauskas/scipy,piyush0609/scipy,efiring/scipy,behzadnouri/scipy,ortylp/scipy