安装 Visual Studio 是否会改变 .Net 中的垃圾收集?
我正在尝试调试一些资源泄漏 - 特别是 oracle 连接。
在我的本地计算机上,当我单步执行 Page_Load() 时,我可以通过监视 v$session 看到在数据库中创建的连接。
一旦我退出 Page_Load,所有连接都会关闭。
在开发服务器(W3k、IIS6)上运行的相同代码不会释放资源 - 根据数据库的连接仍然存在。
我在启用和不启用连接池的情况下尝试过,结果是一样的 - 在本地它很好,在服务器上它泄漏。
我已经验证.net 框架在两个地方都是相同的。 代码也是一样的。 我缺少什么?
I'm trying to debug some resource leaks - oracle connections specifically.
On my local machine, as I step through the Page_Load(), I can see the connections created in the db by monitoring v$session.
As soon as I step out of Page_Load, all the connections are closed.
Same code running on the dev server (W3k, IIS6) does NOT release the resources - connections according to the db are still there.
I've tried this with and without connection pooling enabled, and it's the same - locally it's fine, on the server it leaks.
I have verified that the .net framework is the same in both places & the code is the same as well. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
垃圾收集器具有三种不同的操作模式:服务器 GC、并发工作站 GC 和非并发工作站 GC。 每一种都有不同的行为方式,并针对不同类型的应用程序进行了优化。 这可能是导致不同行为的原因。 具体来说,根据是单个还是多个 CPU,给定设置的行为可能会发生变化。 看看Tess Ferrandez 的博客以获取更详细的解释。
The garbage collector has three different modes of operation: Server GC, Workstation GC Concurrent and Workstation GC Non Concurrent. Each one behaves in a different way and is optimised for different types of applications. This could be what is causing the different behaviour. Specifically, the behaviour can change for a given setting based on whether there is a single or multiple CPUs. Take a look at Tess Ferrandez's blog for a more detailed explanation.
每当您在 .NET 中使用有限资源(例如数据库连接)并希望清理资源时,您应该在对象上显式调用 Dispose() 以确保它得到正确清理和释放。
至于 Visual Studio 改变垃圾收集,我不明白为什么会这样。 垃圾收集器的行为可能会有所不同,因为您在具有不同内存配置文件的不同计算机上运行。 您不能期望垃圾收集器以任何定义的方式运行,尤其是跨机器。 但看起来你有一个更大的问题,就是没有正确处理你的数据库连接。
Whenever you are using limited resources (like database connections) in .NET and are expecting the resources to be cleaned up you should call Dispose() explicitly on the object to ensure that it gets cleaned up and released properly.
As for Visual Studio changing garbage collection, I don't see why it would. The garbage collector may behave differently because you are running on different machine with a different memory profile. You can't expect the the garbage collector to behave in any defined way, especially across machines. But it looks like you have a greater problem of not properly disposing your database connection.