.NET 4.7垃圾收集问题 [英] .NET 4.7 Garbage Collection issue

查看:77
本文介绍了.NET 4.7垃圾收集问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.NET 4.0上运行了一个应用程序。

在使用.NET 4.7的计算机上运行时,存在内存问题(请参阅DotMemory的截图)。

Running on a machine with .NET 4.7, there is a memory issue (see screenshot from DotMemory).

似乎很难找到原因两个版本之间的工作方式不同。

It seems to be hard to find the origin why this works different between both version.

另一个奇怪的事情:我试图调用GC.Collect()来验证是否会使内存可用,但是该方法调用阻止了他所在的线程叫做。

Another strange thing: I was trying to call GC.Collect() to verify if that would make the memory available, but that methodcall blocks the thread wherein he was called.

任何想法?

推荐答案

嗨Stijn Vandenbroucke,

Hi Stijn Vandenbroucke,

感谢您发布此处。

对于您的问题,该应用程序在.net framework 4.0中运行良好,但它在.net framework 4.7中存在内存问题。也许.net框架源代码更改导致问题。可以提供有关哪个代码行导致错误的更多详细信息吗?

For your question, the application works well in .net framework 4.0, but it has a memory issue in .net framework 4.7. Maybe the .net framework source code changed cause the issue. Could provide more details about which code line cause the error?

以下是有关.net框架源代码的链接供您参考。

Here is the link about the .net framework source code for your reference.

< a href ="https://referencesource.microsoft.com/"> https://referencesource.microsoft.com/

对于  GC.Collect(),在大多数情况下,我不建议使用它。当您调用GC.Collect()方法时,运行时执行堆栈遍历以确定可访问的对象和不可访问的对象。它还冻结了应用程序的主线程(以及它创建的任何子线程的
)。换句话说,当调用GC.Collect()方法时,运行时执行所有代的阻塞垃圾收集。

For the GC.Collect(), in most cases, I do not suggest to use it. When you make a call to GC.Collect() method, the runtime performs a stack walk to determine the objects that are reachable and those that aren't. It also freezes the main thread (and also any child threads it created) of the application. In other words, when the GC.Collect() method is called, the runtime performs a blocking garbage collection of all generations.

我认为最好找到导致问题的原因,然后修复它而不是仅使用  GC.Collect()。如果使用.net framework 4.7和.net framework 4.0没有区别,我建议使用.net framework 4.0。

I think it is better to find what caused the issue and then fix it instead of only using GC.Collect(). If there is no difference to use .net framework 4.7 and .net framework 4.0, I suggest to use .net framework 4.0.

最好的问候,

Wendy


这篇关于.NET 4.7垃圾收集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆