sharpener
sharpener

Reputation: 1823

Can mobile dotnet runtime be heap-limited?

Having Xamarin (or maui) iOS application extension (net8.0-ios, ios-arm64), I would like to force it the maximal heap size. Unfortunately apple states that Notification Service Extension can allocate only 24MB.

Is there any way, how to instruct the runtime not to allow the appex assembly (try to) allocate more than given limit?

I have tried the HeapHardLimit multiple ways:

Nothing seems to propagate, as the appex (deployed on physical device) reports 4G available via:

GC.GetGCMemoryInfo().TotalAvailableMemoryBytes

And then (after some allocations) is killed by the iOS with:

kernel EXC_RESOURCE -> App.NSE[10068] exceeded mem limit: ActiveHard 24 MB (fatal)

Upvotes: 0

Views: 105

Answers (1)

Shuowen He-MSFT
Shuowen He-MSFT

Reputation: 647

According to the official explanation(Heap limit), it is recommended to set HeapHardLimit in the runtimeconfig.json file and set MetadataUpdater.IsSupported to false. Since you did not provide the relevant code for runtimeconfig.template.json, you can refer to the following code:

{
   "runtimeOptions": {
      "configProperties": {
         "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
         "System.GC.HeapHardLimit": 209715200
      }
   }
}

Upvotes: 0

Related Questions