UniRx icon indicating copy to clipboard operation
UniRx copied to clipboard

ReactiveDictionary: What is isDisposed used for since it never changes?

Open cathei opened this issue 4 years ago • 1 comments

I was making a class inherits ReactiveDictionary and when I inspect source of it, there is isDisposed.

        [NonSerialized]
        bool isDisposed = false;

and it's used to check if object is disposed.

        public IObservable<Unit> ObserveReset()
        {
            if (isDisposed) return Observable.Empty<Unit>();
            return collectionReset ?? (collectionReset = new Subject<Unit>());
        }

However, Dispose() does not set this variable. In fact, it seems there's nowhere setting this variable. There's disposedValue variable instead, and it reads as same role as isDisposed. but it's private and only used in Dispose().

        #region IDisposable Support

        private bool disposedValue = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    DisposeSubject(ref countChanged);
                    DisposeSubject(ref collectionReset);
                    DisposeSubject(ref dictionaryAdd);
                    DisposeSubject(ref dictionaryRemove);
                    DisposeSubject(ref dictionaryReplace);
                }

                disposedValue = true;
            }
        }

        public void Dispose()
        {
            Dispose(true);
        }

        #endregion

Is this intended or bug? I don't think it's intended, but if it is, it definitely needs some comment explains it.

cathei avatar May 25 '21 18:05 cathei

I think it is a bug #459

hendrik-schulte avatar Jun 03 '21 13:06 hendrik-schulte