Ejemplo n.º 1
0
        /// <summary>
        /// Disposes all object collected by this class and clear the list. The collector can still be used for collecting.
        /// </summary>
        /// <param name="disposeManagedResources">If true, managed resources should be
        /// disposed of in addition to unmanaged resources.</param>
        /// <remarks>
        /// To completely dispose this instance and avoid further dispose, use <see cref="Dispose"/> method instead.
        /// </remarks>
        public void DisposeAndClear(bool disposeManagedResources = true)
        {
            if (disposables == null)
            {
                return;
            }

            for (int i = disposables.Count - 1; i >= 0; i--)
            {
                var valueToDispose = disposables[i];
                if (valueToDispose is IDisposable disposable)
                {
                    if (disposeManagedResources)
                    {
                        disposable.Dispose();
                    }
                }
                else
                {
                    Utilities.FreeMemory((IntPtr)valueToDispose);
                }

                disposables.RemoveAt(i);
            }
            disposables.Clear();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_blob != null)
                {
                    _blob.Dispose();
                    _blob = null;
                }
            }

            if (_gCHandle.IsAllocated)
            {
                _gCHandle.Free();
            }

            unsafe
            {
                if (_ownsBuffer && _buffer != (sbyte *)0)
                {
                    Utilities.FreeMemory((IntPtr)_buffer);
                    _buffer = (sbyte *)0;
                }
            }
        }
Ejemplo n.º 3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         values = null;
     }
     Utilities.FreeMemory(nativeBuffer);
     nativeBuffer = IntPtr.Zero;
 }
Ejemplo n.º 4
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.values = (ComObject[])null;
     }
     Utilities.FreeMemory(this.nativeBuffer);
     this.nativeBuffer = IntPtr.Zero;
 }
Ejemplo n.º 5
0
 protected override unsafe void Dispose(bool disposing)
 {
     if (disposing && this._blob != null)
     {
         this._blob.Dispose();
         this._blob = (Blob)null;
     }
     if (this._gCHandle.IsAllocated)
     {
         this._gCHandle.Free();
     }
     if (!this._ownsBuffer || (IntPtr)this._buffer == IntPtr.Zero)
     {
         return;
     }
     Utilities.FreeMemory((IntPtr)((void *)this._buffer));
     this._buffer = (sbyte *)null;
 }
Ejemplo n.º 6
0
        public void RemoveAndDispose <T>(ref T objectToDispose)
        {
            if (this.disposables == null)
            {
                return;
            }
            this.Remove <T>(objectToDispose);
            IDisposable disposable = (object)objectToDispose as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
            else
            {
                Utilities.FreeMemory((IntPtr)(object)objectToDispose);
            }
            objectToDispose = default(T);
        }
Ejemplo n.º 7
0
 protected override void Dispose(bool disposeManagedResources)
 {
     if (this.disposables != null)
     {
         for (int index = this.disposables.Count - 1; index >= 0; --index)
         {
             object toDisposeArg = this.disposables[index];
             if (toDisposeArg is IDisposable)
             {
                 ((IDisposable)toDisposeArg).Dispose();
             }
             else
             {
                 Utilities.FreeMemory((IntPtr)toDisposeArg);
             }
             this.Remove <object>(toDisposeArg);
         }
     }
     this.disposables = (List <object>)null;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Dispose a disposable object and set the reference to null. Removes this object from this instance..
        /// </summary>
        /// <param name="objectToDispose">Object to dispose.</param>
        public void RemoveAndDispose <T>(ref T objectToDispose)
        {
            if (disposables != null)
            {
                Remove(objectToDispose);

                var disposableObject = objectToDispose as IDisposable;
                if (disposableObject != null)
                {
                    // Dispose the component
                    disposableObject.Dispose();
                }
                else
                {
                    var localData   = (object)objectToDispose;
                    var dataPointer = (IntPtr)localData;
                    Utilities.FreeMemory(dataPointer);
                }
                objectToDispose = default(T);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Disposes all object collected by this class and clear the list. The collector can still be used for collecting.
        /// </summary>
        /// <remarks>
        /// To completely dispose this instance and avoid further dispose, use <see cref="Dispose"/> method instead.
        /// </remarks>
        public void DisposeAndClear()
        {
            if (disposables == null)
            {
                return;
            }

            for (int i = disposables.Count - 1; i >= 0; i--)
            {
                var valueToDispose = disposables[i];
                if (valueToDispose is IDisposable)
                {
                    ((IDisposable)valueToDispose).Dispose();
                }
                else
                {
                    Utilities.FreeMemory((IntPtr)valueToDispose);
                }

                disposables.RemoveAt(i);
            }
            disposables.Clear();
        }