Object references are lost but the resources held are retained

后端 未结 2 1173
隐瞒了意图╮
隐瞒了意图╮ 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:29

    Try

    using (IndentedTextWriter tw = new IndentedTextWriter(internalTW, "    ")) {
      // use it here
    }
    

    resp.

    using (OleDbConnection con = new OleDbConnection(conStr))
    using (OleDbCommand cmd = new OleDbCommand(cmd1, con)) {
      // use it here
    }
    

    At the end of the using block, Dispose() is called on the objects and the resources should be freed...

提交回复
热议问题