0

I have a factory class that keeps an instance of a CrystalReports.Engine.ReportDocument. I'm implementing IDisposable per an awesome SO post, but not sure if the resource is managed or unmanaged.

I'm assuming it's managed since a .NET library, and doing it like this:

using CrystalDecisions.CrystalReports.Engine;

public class ReportFactory: IDisposable {

    public ReportDocument Report { get; private set; }
    private bool IsDisposed { get; set; }

    public void Dispose() {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    private void Dispose(bool freeManagedReousrces) {
        try {
            if (IsDisposed) return;
            if ((freeManagedReousrces)) {
                // Release managed resources.
                if (Report != null) {
                    Report.Dispose();
                }
            }
            // Release un-managed resources.
            // None
        }
        finally {
            IsDisposed = true;
        }
    }

    // No finalizer needed: no unmanaged resources.
}

Please verify that the ReportDocument is a managed resource and that I'm handling it properly.

Community
  • 1
  • 1
mr_plum
  • 2,448
  • 1
  • 18
  • 31

1 Answers1

0

I'm answering my own question. It gave me the Tumbleweed badge for inactivity, so I did more digging and concluded from this post that if an object implements IDisposable it is a managed resource, and I am disposing it properly.

Community
  • 1
  • 1
mr_plum
  • 2,448
  • 1
  • 18
  • 31