F# Equivalent of Destructor

不想你离开。 提交于 2019-12-04 00:28:45

Have you tried looking for F# finalizer?

override x.Finalize() = ...
namespace FSharp.Library  

type MyClass() as self = 

    let mutable disposed = false;

    // TODO define your variables including disposable objects

    do // TODO perform initialization code
        ()

    // internal method to cleanup resources
    let cleanup(disposing:bool) = 
        if not disposed then
            disposed <- true

            if disposing then
                // TODO dispose of managed resources
                ()

            // TODO cleanup unmanaged resources
            ()

    // implementation of IDisposable
    interface IDisposable with
        member self.Dispose() =
            cleanup(true)
            GC.SuppressFinalize(self)

    // override of finalizer
    override self.Finalize() = 
        cleanup(false)

F# Class Library Template

http://blogs.msdn.com/b/mcsuksoldev/archive/2011/06/05/f-class-library-template.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!