jonataslaw / dart-server-nano

A light, fast, and friendly server written in Dart.
MIT License
23 stars 4 forks source link

remove disconnected socket #8

Closed inyong1 closed 5 months ago

inyong1 commented 11 months ago

Only remove the disconnected socket from it's room. Not removing the room

jonataslaw commented 11 months ago

Wow, thank you for your contribution! I really liked the PR, and it seems to improve memory consumption when there are many rooms. Something to consider is just whether this will not overload opening sockets, as it is iterating over all rooms in the constructor. If there are 3000 sockets opening at the same time, and there are 100 rooms open, we will have this same loop running 300000 times. It would be good to have some kind of debouncer, which would prevent this from being done every time the sockets are opened.

inyong1 commented 11 months ago

Maybe we can break the loop after found the room that contains the disconnected socket, so we don't need to loop for whole rooms.

jonataslaw commented 5 months ago

I needed a performative and less error prone way to do this. So I created something I called "RelationalMap" (I'm going to create a package with this too), which guarantees this and all other operations without the chance of memory leaks.

Thanks for your time pointing this out, this PR was instrumental in tracking down this issue.

Since the latest version already has a way around this, I'm closed this PR, but feel free to create issues and open new PRs (and sorry for merging the solution directly into master instead of working here).