LinqToSql DataContext 缓存和内存使用情况
我想知道 LINQ to SQL DataContext
缓存是否使用 WeakReference
或类似的系统以避免在几次请求后使用过多的内存?
此行为是否取决于 ObjectTrackingEnabled
属性?
I was wondering if the LINQ to SQL DataContext
cache use WeakReference
or a similar system to avoid using too much memory after a few requests?
Does this behavior depends on the ObjectTrackingEnabled
property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不;它使用常规引用,因为通常它需要保留对象来执行更改跟踪(正如您提到的),而且还需要身份管理器才能工作。
然而,这不是问题 - 因为您只是简单地使用
DataContext
实例作为一个工作单元。因为否则,变更跟踪器/身份管理器的开销很快就会使数据上下文完全膨胀且无法使用(太慢)。所以;只需简单地使用数据上下文,并在操作完成后收集对象。不要任意保留数据上下文。
有时,您根本不需要数据上下文;对于以读为主的应用程序,还有替代但类似的查询机制。
No; it uses regular references, because normally it needs to keep hold of the objects to perform change tracking (as you mention), but also for the identity manager to work.
This, however, is not a problem - because you are only meant to use a
DataContext
instance briefly, as a unit of work. Because otherwise, the overhead of the change-tracker/identity-manager would soon make the data-context completely bloated and unusable (too slow).So; just use a data-context briefly, and let the objects get collected after your operation is complete. Don't keep hold of a data-context arbitrarily.
Sometimes, you don't need a data-context at all; for read-dominated applications, there are alternative but similar query mechanisms.