V9: uninstalling packages with Doctrine classes doesn't refresh the others

If I uninstall a package with Doctrine classes, the other Doctrine entities from other installed packages don’t get refreshed or get removed from cache or wherever they sit. After uninstalling the package I get:

require(/srv/www/htdocs/c9/application/config/doctrine/proxies/__CG__OtherPackageDoctrineClassName.php): failed to open stream: No such file or directory

Refreshing the entities in System & Settings > Environment > Database Entities > Refresh Entities fixes the problem. But how do I do that during the package uninstall?

Having the “On - Proxy classes will be generated on the fly. Good for development.” option set in System & Settings > Environment > Database Entities > Settings > Doctrine Development Mode also fixes the issue. Although that’s great for development, normal users may not have that option enabled and will always get the error.

Refreshing entities on package uninstall doesn’t help:

$em = DatabaseORM::entityManager();
$manager = $this->app->make(DatabaseStructureManager::class, ['em' => $em]);

That problem happens in both v8 and v9.