njwhites / checkin

A Check-In Application for the Sunshine School
1 stars 0 forks source link

EventEmitter Memory Leak #42

Closed hosley closed 7 years ago

hosley commented 7 years ago

The code below in therapist.ts is throwing (node) warning: possible EventEmitter memory leak detected. 11 listeners added.

ionViewDidEnter() {
    this.studentService.getStudents().then(()=> {
      this.studentList = this.studentService.data;
    }).catch((err) => {
      console.log(err);
    });
    this.userService.getTherapistFavoriteIDs(this.id.toString()).then((result:any) => {
      this.therapistStudents = result;
    }).catch((err) => {
      console.log(err);
    });
  } 

After reading an article on Promises I believe the promises are in the StudentProvider and UserProvider are creating the memory leaks.

A possible solution would be to look into external promise libraries such as those referenced in the article to see if they might provide a solution to the problem

ChrisRogersT commented 7 years ago

I believe this problem stems from trying to set the pouchdb change handler multiple times. Previously I had been setting this change handler in the [provider].getAll() type methods. I believe the intention is that the change handler be set only once. I have since moved the code to set the change handler to the forceInit() function so that they are only called once. This seems to fix the issue but I am not going to close this issue until I've done some more research as I've yet to understand the bug, only get around it.