In Windows this is currently being transformed with MSIX... Whenever that gets a foothold that is. But this is also why it was expected that you were to bundle an uninstaller with your application. It was expected that the developer was to handle cleanup. Obviously too many developers cut corners. The only way around this really is to have a system-wide hook that tracks what files an executable touches, and then have that executable registered to an overall application definition.
It's never going to be perfect. You can be really anal about it where you end up with iOS where, yes, you can sleep pretty well knowing that when you delete an app it has cleaned up after itself. The obvious tradeoff being that it's inherently limiting the scope of what you can do with the app.
I think it's gotten much better in recent years for the Windows crowd. I've been running the same install of 11 for about two years now. Back in the XP days I'd be lucky to be able to make it 6 months without feeling like everything was incredibly bogged down with no way out.