Benutzer-Werkzeuge

Webseiten-Werkzeuge


windows:programming:net:dispose

Dispose Pattern

Base Class

abstarct class BaseClass{
    private bool _disposed = false
 
    protected virtual void Dispose(bool disposing){
        if(_disposed){
            return;
        }
        if(!disposing){
            //Free managed objects
        }
        //Free any other objects
        _disposed = true;
    }
}

Implement Class

class ImplClass : BaseClass{
    private bool _disposed = false;
 
    protected override void Dispose(bool disposing){
        if(_disposed){
            return;
        }
        if(disposing){
            //Free managed objects
        }
        //Free any other objects
        _disposed = true;
        base.Dispose(disposing);
    }
}
windows/programming/net/dispose.txt · Zuletzt geändert: 2017/11/07 11:01 von raiser