I'm using C# .NET 3.5 ... and I've been working to decouple a BLL object by moving database related activity into a seperate worker object. The worker object adds entities to the database and events a success or failure message back to a BLL object.
When I instance the worker object in the BLL I wire up the worker's events and set the BLL's event handler using the event += delegate(eventhandler) syntax.
I've heard that if I don't explicitly unwire the listeners with the -= syntax when the worker is disposed that there is a potential for memory leaks.
All of this processing occurs in a windows service that picks up messages from a queue and calls the appropriate BLL object ... I'm worried that I might be introduce a memory leak into this process.
Subscribing to an event adds a reference from the subscriber to the provider.
x.Event += y.handler means that x now holds a reference to y
If x has a longer lifespan than y then y cannot be garbage collected until all references to x have disappeared.
In your case you are listening to events from the workers in the BLL (if I understand you correctly) then you have references to the workers remaining in the BLL unless you explicity unsubscribe.
However, if you are finishing with the worker at the same time as the BLL then it won't actually matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With