I found that using the AngularFireAuthModule
from '@angular/fire/auth';
causes a memory leak that crashes the browser after 20 hours.
Version:
I use the latest version updated today using ncu -u for all packages.
Angular Fire: "@angular/fire": "^5.2.3",
Firebase version: "firebase": "^7.5.0"
,
How to reproduce:
I made a minimum reproducible code on StackBliztz editor
Here is the link to test the bug directly StackBlizt test
Symptom:
You can check yourself that the code does nothing. It just prints hello world. However, the JavaScript memory used by the Angular App increases by 11 kb/s (Chrome Task Manager CRTL+ESC). After 10 hours leaving the browser open, the memory used reaches approx 800 mb (the memory footprint is around twice 1.6 Gb!)
As a result, the browser runs out of memory and the chrome tab crashes.
After further investigation using the memory profiling of chrome under the performance tab, I clearly noticed that the number of listeners increases by 2 every second and so the JS heap increases accordingly.
Code that causes the memory leak:
I found that using the AngularFireAuthModule
module causes the memory leak whether it is injected in a component
constructor or in a service
.
import { Component } from '@angular/core';
import {AngularFireAuth} from '@angular/fire/auth';
import {AngularFirestore} from '@angular/fire/firestore';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'memoryleak';
constructor(public auth: AngularFireAuth){
}
}
Question:
It could be a bug in the implementation of FirebaseAuth and I already open a Github issue, but I am looking for a workaround for this issue. I am desperate for a solution. I don't mind even if the sessions across tabs not synchronized. I don't need that feature. I read somewhere that
if you don't require this functionality, the Firebase V6 modularization efforts will allow you to switch to localStorage which has storage events for detecting changes cross tabs, and possibly will provide you the ability to define your own storage interface.
If that's the only solution, how to implement that?
I just need any solution that stops this unnecessary increase of listener because it slows down the computer and crashes my app. My app needs to run for more than 20 hours so it now unusable due to this issue. I am desperate for a solution.