palacaze / sigslot

A simple C++14 signal-slots implementation
MIT License
709 stars 97 forks source link

Potential memory leak when weak_ptr compatible object used. #38

Open 4e4o opened 1 year ago

4e4o commented 1 year ago

When signal connected to multiple shared_ptr objects there is no way to delete dead slots with dead objects without invoking slots. Every signal::connect call will increase slot instances. I think signal::connect with weak_ptr should check for dead slots and remove them.

4e4o commented 1 year ago

https://github.com/palacaze/sigslot/pull/39

palacaze commented 1 year ago

Hi, I agree that dead slots removal gets delayed until the next signal emission. Your proposed fix seems fine to me, but I would like to know if this is a real problem for you or just from a theoretical standpoint?

4e4o commented 1 year ago

Hi, I agree that dead slots removal gets delayed until the next signal emission. Your proposed fix seems fine to me, but I would like to know if this is a real problem for you or just from a theoretical standpoint?

Yes, there is a real problem. I have tcp server which produces tcp clients and i want to close all tcp clients when server closed. So i connect server stop signal to every new tcp client deleter, but signal emition is never happen actualy, only at program exit so i have a memleak.