Reclaiming Native Images
Native images can take up a significant amount of space on a user's hard disk drive. When a native image ceases to provide value it should be reclaimed to free up system resources. Native images can be reclaimed automatically by the .NET Framework or uninstalled manually by developers or administrators.
In addition to tracking just-in-time compiler (JIT) usage to determine when to create native images, the .NET Framework also tracks native image use to determine when native images can be reclaimed. Any native image that was created automatically by the .NET Framework, and that has not been used for an extended period of time, is automatically reclaimed by the Native Image Task during computer idle time. (The implementation of this policy is designed to account for extended idle times such as long vacations.)
In scenarios where automatic native image creation is not available, developers who manually run the Native Image Generator (Ngen.exe) during application installation are responsible for removing native images by using the Ngen Uninstall command when the application is uninstalled. Otherwise, the native images remain on the user's hard disk indefinitely.
If a native image is created automatically by the .NET Framework, and then recreated manually by using NGen.exe, the native image is no longer reclaimed automatically.
The Ngen service maintains a list of dependencies so that shared components are removed only when all assemblies that depend on them have been removed. In addition, a shared component is not removed if it has been installed as a root.
The following command uninstalls all native images for Assembly, even if they were installed with the /Profile or /Debug options:
ngen Uninstall Assembly
If you installed a native image with the /Profile or /Debug options, you can remove individual scenarios. For example, the following command removes only the image that was created for profiling:
ngen Uninstall Assembly /Profile
The following command reclaims a native image for a specific version of an assembly. If the image was compiled for multiple scenarios, all scenario versions are removed.
ngen uninstall "ClientApp, Version=184.108.40.206, Culture=neutral, PublicKeyToken=3c7ba247adcd2081, processorArchitecture=MSIL"