'Workstation GC in .NET Core 3.1 is not working for AWS Lambda

I am creating an AWS Lambda function with .NET Core 3.1 and I have a problem with increased memory consumption. For this reason, I wanted to use Workstation GC as this setting reduces memory consumption by several times.

I set ServerGarbageCollection setting to false in the *.csproj file:

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AWSProjectType>Lambda</AWSProjectType>
    <!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <ServerGarbageCollection>false</ServerGarbageCollection>
  </PropertyGroup>

and after building the project in *.runtimeconfig.json these lines have been added

"configProperties": {
      "System.GC.Server": false
    }

after these changes, when checking the garbage collector mode, the GCSettings.IsServerGC property is always true.

I tested it on a regular console application and it works fine, but as soon as I connect the aws lambda libraries, the application becomes like a class library and it is impossible to change this setting. I searched the aws documentation but didn't find anything that could help me.

q: how do I enable Workstation GC in AWS Lambda?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source