Answer the question
In order to leave comments, you need to log in
Do I need to take care of freeing memory with EventEmitter?
Example. There are 2 emitters, one contains the other. You need to subscribe the top one to the bottom one so that the events of the bottom one are transferred to the top one.
class Up extends EventEmitter {
down = new EventEmitter();
constructor() {
down.on('event', () => this.emit);
}
}
Answer the question
In order to leave comments, you need to log in
Maybe I'm not fully competent in this matter and I myself am mistaken, but the leak is not visible
. A memory leak can occur if a "long-lived" object refers to a "short-lived" one
when you write:
at down in the events array, a link to the emit method in an instance of the Up class is added, if there is no instance of the Up class, then there will be no links to it from down. The problem can be if an instance of the Up class also subscribes to events in down
If anything, then sorry for the confusion.
If someone reads and sees an error in this answer, I urge you to correct it, it will also be useful to me)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question