corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. #132

Open quantang opened 3 years ago

quantang commented 3 years ago

Hello @sekur,

I got the following warning when I try to use yang.js to "eval" the JSON data repeatedly.

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 101 change listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit

I can understand that we attached some events with the schema, such as "change", on the Model level. So I tried to release the model by call "delete" function, but it looks like the events didn't get removed from the schema.

Maybe the way that I use "eval" is inappropriate, but I guess the events should be got "off" when the model is deleted.

Here is my code: const model = YangSchema.schema.eval(_.cloneDeep(defaultData)); const result = doSomethingWithModel(model); model.delete();

Any suggestion or feedback is welcome. Cheers.