Reputation: 1823
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:
in a csproj
as:
<ItemGroup>
<!-- Try to limit heap to 20M -->
<RuntimeHostConfigurationOption Include="System.GC.HeapHardLimit" Value="20971520" />
</ItemGroup>
in runtimeconfig.template.json
as:
{
"configProperties": {
"System.GC.HeapHardLimit": 20971520
}
}
in the code when UNNotificationServiceExtension
is created as:
AppContext.SetData("GCHeapHardLimit", (ulong) 20 * 1024 * 1024)
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
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