LinqToSql DataContext 缓存和内存使用情况

发布于 2025-01-01 07:50:18 字数 257 浏览 1 评论 0原文

我想知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹微笑 2025-01-08 07:50:18

不;它使用常规引用,因为通常它需要保留对象来执行更改跟踪(正如您提到的),而且还需要身份管理器才能工作。

然而,这不是问题 - 因为您只是简单地使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文