我可以在 .NET 应用程序中使用较小的源数据集模拟内存稀缺情况以找出内存泄漏吗?

发布于 2024-08-13 03:47:32 字数 290 浏览 4 评论 0原文

我有一个应用程序,可以预见地在非常非常大的数据集上生成内存不足错误 - 我们正在尝试通过优化应用程序的内存管理来解决该问题,但是所涉及的非常非常大的数据集需要很长时间运行(天)很难迭代测试周期并凭经验发现问题。

暂时搁置应用程序性能问题 - 这是任务列表中正确的应用程序行为之后的下一个问题:

是否有一种简单的方法来限制应用程序在运行时可用的内存量Visual Studio 中的调试模式,以便强制仅在非常大的数据集上自然发生的 OutOfMemory 错误发生在较小的数据集上?

I have an application which predictably generates out-of-memory errors on very, very (very) large datasets - we're trying to fix the problem by optimizing the app's memory management, but the very, very large datasets in question require so long to run (days) that it's difficult to iterate through testing cycles and find the problem empirically.

Leaving aside for a moment the question of application performance - that's next on the task list after correct application behavior:

Is there an easy way to restrict the amount of memory an application has available when running in debug mode in Visual Studio, so as to force OutOfMemory errors which naturally occur only on very large datasets to instead occur on a smaller dataset?

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

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

发布评论

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

评论(4

北城挽邺 2024-08-20 03:47:32

只需在程序启动时自行分配一大块即可 - 在执行其他操作之前。

要保留大约 500MB 的可用空间(对于 32 位进程):

byte[] OutOfMemory = new Byte[int.MaxValue - ((1024 ^ 2) * 500)];

Simply Allocate a large chunk yourself at program startup - before you do anything else.

To keep around 500MB free (for a 32 bit process):

byte[] OutOfMemory = new Byte[int.MaxValue - ((1024 ^ 2) * 500)];
傾城如夢未必闌珊 2024-08-20 03:47:32

您是否尝试过简单地从一开始就分配大量内存,并在程序执行期间保留它?

这将减少应用程序其余部分的可用内存。

Have you tried simply allocating a large amount of memory to begin with, and keeping it for the duration of the program execution?

This would reduce the available memory for the rest of the application.

許願樹丅啲祈禱 2024-08-20 03:47:32

一个可行的技巧是在程序启动时分配一个更大的缓冲区。只要你保留对它的引用,这样它就不会被GCed,这就会得到你想要的。

One trick that should work would be to allocate a larger buffer right when the program starts. As long as you keep a reference to it so that it's not GCed, that will get you want you want.

岁月苍老的讽刺 2024-08-20 03:47:32

我会得到一个内存分析器,并尝试在生产中出现问题之前人为地重新创建问题。 ANTS 内存分析器非常适合:

http://www.red-gate .com/products/ants_memory_profiler/index.htm

虽然价格昂贵,但试用可能可以解决这个问题。

I'd get a memory profiler and try and re-create the issue artificially before it bites you in production. ANTS memory profiler is pretty good for that:

http://www.red-gate.com/products/ants_memory_profiler/index.htm

It's expensive but the trial would probably do for that issue.

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