neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.08k stars 892 forks source link

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

Open cathei opened 3 years ago

cathei commented 3 years ago

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.

hendrik-schulte commented 3 years ago

I think it is a bug #459