向 WCF 发出肥皂请求后,对象在内存中保留多长时间?
我想知道在肥皂请求期间实例化的对象(不实现 IDisposable )在内存中保留多长时间?
例如:
...
public GetRecordsResponse GetRecords(GetRecordsRequest request)
{
GetRecordsTransaction transaction = new GetRecordsTransaction();
GetRecordsResponse response = transaction.GetResponse(request);
return response;
}
...
事务会在内存中保留多长时间?
soap 发送响应后?会话(如果 wcf 中存在)?
I was wondering how long do objects instantiated during a soap request ( which do not implement IDisposable ) stay in memory?
for example:
...
public GetRecordsResponse GetRecords(GetRecordsRequest request)
{
GetRecordsTransaction transaction = new GetRecordsTransaction();
GetRecordsResponse response = transaction.GetResponse(request);
return response;
}
...
How long would the transaction stay in memory?
As soon as soap sends the response? session (if that exists in wcf)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现 IDisposable 与托管内存关系不大。垃圾收集是关于清理托管内存;但 IDisposable 旨在允许控制释放非托管资源。
从您的代码示例中,您无法保证对象在内存中存在多长时间,并且您绝对不应该对垃圾收集器在不再引用这些对象后多久(或晚)回收这些对象的内存做出任何假设通过你的代码。
我可以问你为什么需要知道吗?听起来好像您期望事务在垃圾收集时具有某种行为,而您真正想要的是显式回滚或提交它们。如果您能解释您的根本问题,可能有助于澄清问题。
Implementing IDisposable has little to do with managed memory. Garbage collection is about cleaning up managed memory; but IDisposable is intended to allow control of releasing unmanaged resources.
From your code sample, you have no guarantee of how long your objects are in memory for, and you should definitely not make any assumptions about how soon (or late) the garbage collector will reclaim the memory for those objects once they are no longer referenced by your code.
May I ask why you need to know? It sounds as though you are expecting your transactions to have some sort of behaviour at the point of garbage collection, when what you really want is to explicitly rollback or commit them. If you could explain your root problem, that might help clarify the question.
它们没有被缓存。它们可能会暂时没有被垃圾收集。
They are not cached. They may happen not to be garbage collected for a while.