I just compile simple code in release mode both in Web Api and Console Application and I got different results
Web Api
var builder = WebApplication.CreateBuilder(args);
WeatherForecast _weatherForecast = new WeatherForecast();
_weatherForecast = null;
builder.Services.AddControllers();
Console Application
WeatherForecast weatherForecast = new WeatherForecast();
weatherForecast = null;
Then I just inspected those dlls using ILSpy tool and saw completely different result. For console application Jit compiler removed weatherForecast = null but for web api it remains. So it means that in console application does not make sense to set reference type variable to null to make some help for GC in advance