// License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. namespace Intel.RealSense { using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; public class FramesReleaser : ICompositeDisposable { private readonly List disposables = new List(); /// /// Add an object to a releaser (if one is provided) and return the object /// /// type implementing /// Optional to add and object to, or null /// object to release /// the [Obsolete("This method is obsolete. Use AddDisposable method instead")] public static T ScopedReturn(FramesReleaser releaser, T obj) where T : IDisposable { if (releaser != null) { releaser.AddDisposable(obj); } return obj; } /// /// Add an object to a releaser /// /// object to add public void AddDisposable(IDisposable disposable) { disposables.Add(disposable); } private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { disposables.ForEach(d => d?.Dispose()); disposedValue = true; } } ~FramesReleaser() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } } }