views:

98

answers:

1

I noticed that NerdDinner doesn't dispose of the DataContext -- ever. That seems very strange to me. They have a Repository class that creates a private member of the data context, which hangs around for the lifetime of the repository class -- and who knows how long that is, since it's created at the time of the controller's construction again as a private member variable and never dereferenced. When is the controller dereferenced?

I believe the issue revolves around passing IQueryable types, which must have an open connection at the time you iterate over them. But doesn't this then mean that there will be some dangling open connections?

+1  A: 

Make the Repository itself disposable. Dispose the data context when the repository is disposed. Override Controller.Dispose and dispose the repository there. The controller is still alive when the view is executed.

Craig Stuntz