3 ms·
That doesn't sound quite right. When a object attaches a handler to an event, that creates a reference from the event source to the event listener. Until the ha
by cpitman 4y ago
That doesn't sound quite right. When a object attaches a handler to an event, that creates a reference from the event source to the event listener. Until the handler is unattached, the event listener shouldn't be collected by GC, since it is technically still alive.
This lead to one of the more entertaining C# memory leak stories, where Princeton's entry to the DARPA Grand Challenge ended up failing because every frame they detected obstacles, created a class for each, and subscribed each obstacle object to an event. They missed that the event subscription was keeping those objects alive, and every piece of tumbleweed in the desert helped leak memory until the car just stopped! https://www.codeproject.com/Articles/21253/If-Only-We-d-Used-ANTS-Profiler-Earlier https://www.codeproject.com/Articles/21253/If-Only-We-d-Used...