实体框架 - 处置后的 _objectTypeCount
在我的网站中,我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在观看
ObjectContext
类的 static 变量:我不知道其目的是什么。 (它计算在应用程序或会话生命周期内创建 ObjectContext 的频率,或者其他什么???)
但是因为它是静态,所以你无法从不断增加的计数器中得出你的
ObjectContext 实例尚未从内存中删除。
编辑
此计数器和代码中的
ObjectID
显然与所谓的BID 跟踪。 “BID”代表“内置诊断”。上述内部代码构造出现在许多 ADO.NET 类中。它仅用于跟踪这些类中的方法调用,并出现在如下跟踪函数中:_objectTypeCount
和ObjectID
只是为类型的实例提供名称(或唯一 ID)用于跟踪输出。除了跟踪之外,它在
ObjectContext
类内部没有任何功能意义。You are watching a static variable of the
ObjectContext
class: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:The
_objectTypeCount
and theObjectID
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.