Bit OT: Events and garbage collection

Bit OT: Events and garbage collection

Old forum URL: forums.lhotka.net/forums/t/4707.aspx


ajj3085 posted on Thursday, April 17, 2008

Hi,

Moving my BOs to use Linq for data access, I've found that I have to listen for property change events to update the BO's copy of the primary key after insert.

So I have something like this..

// Some other code
Data.Product product = new Data.Product();
product.PropertyChanged +=
    delegate( object sender, PropertyChangedEventArgs e ) {
       productId = product.ProductId.Value;
    };
db.Products.InsertOnSubmit( product );
// other code

My question is this; my BO is listening for an event from the data object, which eventually (after the the DataPortal call completes) will have no references.. but will product be garbage collected properly, or do I need to somehow unhook the event handler in my BO?

I know there are issues with events that can cause objects not to be collected properly.. I just don't understand the details.

Thanks
Andy

Copyright (c) Marimer LLC