Hey there. I've downloaded a couple of apps to test and trial, and deleted them. I didn't know about the codes that are left behind until recently, and how it affects the speed.
Unfortunately there's no way that I can find out what were these apps that I downloaded previously. Since they all come and stay in the theme codes, I was wondering if downloading a new theme will sort of 'refresh' the codes, and only leave behind codes that are actually being used? Would that work?
You can get back to app's support and can ask the support to remove the complete code or the files which gets added by default after installing the app. The app support will assist you in removing the code from your store.
Most Apps will install themselves in a new theme, but some may need manual installation/corrections. And yes, only those apps which are currently installed will be able to do it. Also consider whether you've done some theme code modifications.
Otherwise, it's a fastest way to get rid of the old apps remains. If it's the same theme (and similar version) you may simply copy/paste contents of your settings_data.json config to transfer all theme configuration settings.
And finally, you will still have your current theme as unpublished backup just in case.