-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak caused due to create too many instances of Api object #11
Comments
Yes, I also saw this on 1-2 occasions. I kind of disagree for a shared singleton pool though, I think we shouldn't fix developers' mistakes with ugly patches (ugly = i don't like singletons). And imo two So I would propose:
|
Marking as docs, not quite open to singleton polls without as specific (switched off by default), flag for this. |
Ok, not sure wtf to add to the documentation here. Where is the current getting started lacking that can be adjusted? (Asking since my first instinct was just to close is) |
I guess in this page there can be a section about teardown an instance and mention if you don't teardown it, the instance will live in memory and may not be GC'ed and therefore could cause memory leak. Or another page about all the thing that developers should be aware of and this will be one of section. |
Currently every instance of the Api object will create and maintain a web socket connection.
It never disconnects itself and will attempt to reconnect if connection dropped for any reason.
We have an issue that developers are not aware of this behavior and construct a new instance of Api on every method call.
Because the Api object can never automatically GC'ed by JS due to the fact the ws connection is open, this results connection leaks, memory leaks, and unstable application.
I don't know what is the best way to solve this issue other than code review.
I wonder if have polkadot.js enforce shared Api object will help. i.e. have a shared pool of all created api instances, return existing one if parameters (ws url) matches.
The text was updated successfully, but these errors were encountered: