实体框架 - 处置后的 _objectTypeCount

发布于 2024-11-30 02:17:09 字数 282 浏览 2 评论 0原文

在我的网站中,我有一个 ObjectContextStorage,它将所有 ObjectContext 保存在其中。 http 请求完成后,我丢弃此存储(将其从 HttpContext.Current.Items 中删除)并在此存储中处置 ObjectContext。

现在,当我调试并查看 ObjectContext 的 _objectTypeCount 时,当我重新加载网站时,它会不断升高,而我会认为旧的 ObjectContext 已被处置?

为什么旧的 ObjectContext 在处理后仍然在我的内存中?

In my website I've a ObjectContextStorage which keeps all the ObjectContext in them. After the http-request is done I throw away this storage (remove it from HttpContext.Current.Items) and dispose the ObjectContexts in this storage.

Now when I debug and look at the _objectTypeCount of my ObjectContext it keeps raising when I reload my website while I would think the old ObjectContext is disposed??

Why is the old ObjectContext still in my memory after disposing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

任谁 2024-12-07 02:17:09

您正在观看 ObjectContext 类的 static 变量:

private static int _objectTypeCount; // Bid counter
internal readonly int ObjectID = System.Threading.Interlocked.Increment(
                                                       ref _objectTypeCount);

我不知道其目的是什么。 (它计算在应用程序或会话生命周期内创建 ObjectContext 的频率,或者其他什么???)

但是因为它是静态,所以你无法从不断增加的计数器中得出你的ObjectContext 实例尚未从内存中删除。

编辑

此计数器和代码中的ObjectID显然与所谓的BID 跟踪。 “BID”代表“内置诊断”。上述内部代码构造出现在许多 ADO.NET 类中。它仅用于跟踪这些类中的方法调用,并出现在如下跟踪函数中:

EntityBid.Trace("<ec.EntityCommandDefinition.CreateCommand|ADV> %d#\n",ObjectID);

_objectTypeCountObjectID 只是为类型的实例提供名称(或唯一 ID)用于跟踪输出。

除了跟踪之外,它在 ObjectContext 类内部没有任何功能意义。

You are watching a static variable of the ObjectContext class:

private static int _objectTypeCount; // Bid counter
internal readonly int ObjectID = System.Threading.Interlocked.Increment(
                                                       ref _objectTypeCount);

I've no clue what's the purpose of this. (It counts how often an ObjectContext has been created during an application or session lifetime, or something ???)

But because it's static you cannot conclude from an ever increasing counter that your ObjectContext instances haven't been removed from memory.

Edit

This counter and the ObjectID in the code apparently has to to with so called BID tracing. "BID" stands for "Built-In-Diagnostics". The internal code construct above occurs in many ADO.NET classes. It is used just for tracing method calls in those classes and occurs in trace functions like this:

EntityBid.Trace("<ec.EntityCommandDefinition.CreateCommand|ADV> %d#\n",ObjectID);

The _objectTypeCount and the ObjectID are just there to give an instance of a type a name (or unique ID) for tracing output.

Aside from tracing it has no functional meaning inside of the ObjectContext class.

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