我有一个简单的序列表达式,它使用了我想在完成后清理的资源:
type MyObject() =
member this.Items =
seq {
use resource = ResourcePool.Get()
let c = resource.ValueCount
if c > 0 then
for i in 0 .. c - 1 do
yield resource.GetValue i
}
如果我然后使用序列来迭代,比如说,在项目的中途,资源什么时候被处置?
例如:
// ...
let foo = MyObject
let item = foo.Items |> Seq.find ( fun i -> i.Name = "name" )
// ...
resource
Seq.find 完成后会被释放吗?还是我需要重新考虑我的资源管理策略?