Object references are lost but the resources held are retained

后端 未结 2 1171
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 12:49
IndentedTextWriter tw = new IndentedTextWriter(internalTW, \"    \");

Object referenced by \'tw\' is lost, but related resources are not disposed h

2条回答
  •  不思量自难忘°
    2021-01-15 13:31

    The types all implement IDisposable, and thus it is the caller's responsibility to call Dispose() like e.g.

    using(var tw = new IndentedTextWriter(internalTW, "    ")) {
        // do something with tw
    }
    

    or by explicitly calling Dispose() in a finally block.

提交回复
热议问题