Application Insights 在 Win2D 游戏中导致不必要的 GC

Application Insights causing unnecessary GC in Win2D game

所以我在开发 Win2D 游戏时注意到偶尔会跳过一些帧。我以为是 GC,所以我拍摄了几个内存快照以查看发生了什么。在解决了我的部分问题并在游戏开始时分配了我所有的内存之后,我注意到很多 Task< IReadOnlyList< Windows.Storage.StorageFile>> 对象是仍在游戏过程中创建。这也发生在一个空的通用应用程序项目中,环顾四周后,我发现默认情况下启用了 Application Insights 并导致了这一切。

我对 Application Insights 了解不多,但拥有它似乎很不错。 所以我的问题是:我是否仍可以使用 Application Insights 但阻止它创建所有这些任务对象和访问文件系统?

ApplicationInsights 使用 PersistenceChannel that whenever telemetry item is generated stores it on disk and than reads it back and sends (and in case of no internet connection, stores it back and tries later). You can replace in with InMemoryChannel 只会发送遥测数据(但如果出现故障,遥测项目将会丢失)。这个实现应该更轻量级,因为它不需要存储访问,但请注意它也没有重试策略。 所以一开始你会这样做:

TelemetryConfiguration.Active.Channel.Dispose(); // you may need to cast it here to persistence channel TelemetryConfiguration.Active.Channel = new InMemoryChannel();