假设我有一组这样简单的类:
class Bus
{
Driver busDriver = new Driver();
}
class Driver
{
Shoe[] shoes = { new Shoe(), new Shoe() };
}
class Shoe
{
Shoelace lace = new Shoelace();
}
class Shoelace
{
bool tied = false;
}
Run Code Online (Sandbox Code Playgroud)
A Bus有一个Driver,Driver有两个Shoe,每个Shoe有一个Shoelace.一切都很傻.
后来我决定对它进行一些操作Shoelace可能是多线程的,所以我添加了一个EventWaitHandle用于与之通信的线程.所以Shoelace现在看起来像这样:
class Shoelace
{
private AutoResetEvent waitHandle = new AutoResetEvent(false);
bool tied = false;
// ... other stuff .. …Run Code Online (Sandbox Code Playgroud) 根据我的经验,似乎大多数人会告诉你强制垃圾收集是不明智的,但在某些情况下,你正在使用大型对象,这些对象并不总是在0代收集,但内存是一个问题,是它可以强制收集?这样做有最好的做法吗?
我已经阅读了很多.NET性能文章,这些文章描述了Gen1,Gen2垃圾收集和几代人幸存的对象.
为什么物品能够在收藏中存活下来?
什么是钉扎?
我如何了解更多相关信息?