On Tue, 2009-06-16 at 17:01 -0700, greyman wrote: > The thing I find confusing and what set me down the wrong path with > the usage pattern I employed for DataContext was that it looks like it > should be an application lifetime type object.
I would have agreed with you, prior to reading the documentation, but then I started looking at the object tracking implementation. In order to perform updates, DataContext needs to track *every* entity[0] object it returns, and additionally track property changes on these objects. If you have DataContext living longer than a method call, and reuse it, it would not seem that unusual for it to be tracking a *huge* number of objects. (Specifically, I wouldn't be surprised if it were tracking millions of objects if it were used with a busy web service within a few days time, if not sooner.) Needing to track large quantities of objects will increase pressure on the GC, increase memory use, and slow down the application (as more OS disk cache is used as memory use increases). It only gets worse when you realize that there's no mechanism to clear the tracked object cache, meaning you'd have to create a new DataContext instance at some point anyway, just to clear out unused entities... > It's arguable the > identity management and query caching in DbLinq won't be of much > benefit if the DataContext is only used for single units of work. I'm not sure about identity management, but I'm dubious about query tracking (as I've mentioned numerous times), as the only way to usefully cache the query is to use a global cache, which could have similar unbounded growth issues. On the other hand, CompiledQuery doesn't suffer from these problems, as it's held by the developer, doesn't refer to a DataContext (it needs to be provided to the CompiledQuery on each delegate call), and isn't "invisible global memory use." But this is a discussion for another time.... - Jon [0] "entity" defined as "MappingSource.GetModel(Type) returns non-null for the entity's type." --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DbLinq" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dblinq?hl=en -~----------~----~----~----~------~----~------~--~---
