Why is the datacontext never disposed

Nov 20, 2009 at 4:09 PM

It appear that the dinner repository creates an instance of a private NerdDinnerDataContext member.  Since a DataContext implements IDisposable.  Should we not then be disposing of it when we're finished?  Since it's private member, when would we be finished with it?  It woudl seem that the Dinner Repository should in turn also implement IDisposable.

If that's the case, then the DinnerController should not be creating a private dinnerRepository in the ctor, but rather should be creating local dinnerRepository instances as part of a using block.

Am I missing something obvious about the disposal of the Data Context?

 

Coordinator
Nov 20, 2009 at 4:24 PM
It gets garbage collected (Dispose() gets called) quickly after.

On Fri, Nov 20, 2009 at 9:09 AM, rshillington <notifications@codeplex.com> wrote:

From: rshillington

It appear that the dinner repository creates an instance of a private NerdDinnerDataContext member.  Since a DataContext implements IDisposable.  Should we not then be disposing of it when we're finished?  Since it's private member, when would we be finished with it?  It woudl seem that the Dinner Repository should in turn also implement IDisposable.

If that's the case, then the DinnerController should not be creating a private dinnerRepository in the ctor, but rather should be creating local dinnerRepository instances as part of a using block.

Am I missing something obvious about the disposal of the Data Context?

 

Read the full discussion online.

To add a post to this discussion, reply to this email (nerddinner@discussions.codeplex.com)

To start a new discussion for this project, email nerddinner@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Scott Hanselman
http://www.hanselman.com
Nov 20, 2009 at 4:33 PM

Is this a new pattern, that we can count on Garbage Colleciton in a timely fashion?  It seems to me that in a high volume site there would be many more new connections created before the old ones are GC'ed.

Is there a specific call to GC.Collect that I'm missing somewhere?

Coordinator
Nov 20, 2009 at 4:36 PM
Nope, it's just relying on GC to do it's job. You're technically correct, but until it becomes a problem I don't sweat it. In this case, it's an optimization that I don't think it's important until it doesn't work.

That said, I'll ask Phil to make sure I'm not completely full of ****. ;) I'm usually a fan of Dispose() everywhere.

On Fri, Nov 20, 2009 at 9:33 AM, rshillington <notifications@codeplex.com> wrote:

From: rshillington

Is this a new pattern, that we can count on Garbage Colleciton in a timely fashion?  It seems to me that in a high volume site there would be many more new connections created before the old ones are GC'ed.

Is there a specific call to GC.Collect that I'm missing somewhere?

Read the full discussion online.

To add a post to this discussion, reply to this email (nerddinner@discussions.codeplex.com)

To start a new discussion for this project, email nerddinner@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Scott Hanselman
http://www.hanselman.com