小编MZy*_*tza的帖子

在FileHelper中跳过列

使用.Net 的FileHelper库,我可以以某种方式跳过源文件中的多个列吗?

根据文档和示例,我必须为所有列添加字段.唉,我有一个excel表,有216列可以导入,只需要13个.

.net csv filehelpers

8
推荐指数
2
解决办法
3346
查看次数

垃圾收集器不会收集使用创建的对象

我想测试不正确的对象引用并编写一个总是失败的测试.我将测试简化为以下行为:

    [Test]
    public void ScopesAreNotLeaking()
    {
        WeakReference weakRef;
        Stub scope = null;
        using (scope = new Stub())
        {
            weakRef = new WeakReference(scope);
        }
        scope = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
        Assert.That(weakRef.Target, Is.Null);
    }
Run Code Online (Sandbox Code Playgroud)

然而,该测试在不使用的情况下执行相同的操作:

    [Test]
    public void ScopesAreNotLeaking()
    {
        WeakReference weakRef;
        Stub scope = new Stub();
        weakRef = new WeakReference(scope);
        scope = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
        Assert.That(weakRef.Target, Is.Null);
    }
Run Code Online (Sandbox Code Playgroud)

使用的存根类很简单:

class Stub : IDisposable
{
    public void Dispose()  {}
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下这种行为,或者 - 甚至更好 - 有一个想法,如何确保对象被垃圾收集?

PS:如果之前有过类似的问题,请耐心等待.我只检查了标题中使用的那些问题.

c# garbage-collection

6
推荐指数
2
解决办法
475
查看次数

标签 统计

.net ×1

c# ×1

csv ×1

filehelpers ×1

garbage-collection ×1