1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // PROPRIETARY/CONFIDENTIAL
3 // This software is the confidential and proprietary
4 // information of SAMSUNG ELECTRONICS ("Confidential Information"). You shall
5 // not disclose such Confidential Information and shall use it only in
6 // accordance with the terms of the license agreement you entered into with
7 // SAMSUNG ELECTRONICS.
11 using System.Collections.Generic;
16 public class DisposeQueue
18 private static DisposeQueue _disposableQueue = new DisposeQueue();
19 private List<IDisposable> _disposables = new List<IDisposable>();
20 private Object _listLock = new object();
21 private delegate int ProcessDisposablesDelegate(IntPtr ptr);
22 private ProcessDisposablesDelegate _disposequeueProcessDisposablesDelegate;
24 private DisposeQueue()
26 _disposequeueProcessDisposablesDelegate = new ProcessDisposablesDelegate(ProcessDisposables);
27 Application.Instance.AddIdle(_disposequeueProcessDisposablesDelegate);
34 public static DisposeQueue Instance
36 get { return _disposableQueue; }
39 public void Add(IDisposable disposable)
43 _disposables.Add(disposable);
47 private int ProcessDisposables(IntPtr ptr)
51 foreach (IDisposable disposable in _disposables)