RxJS .subscribe() without arguments still cause memory leak?

I know this will cause memory leak because there is no unsubscription


question is:
If I do not pass any observer into subscribe method, is it still causing memory leak? thanks


>Solution :

Yes, it’s the same.

You can check it inside source code of Observable:

    observerOrNext?: Partial<Observer<T>> | ((value: T) => void) | null,
    error?: ((error: any) => void) | null,
    complete?: (() => void) | null
  ): Subscription {
    const subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);

There is SafeSubscriber class instance creation method if no arguments passed. And subscription works normally as you’d expect.

Leave a Reply