简体   繁体   English

是否可以在没有任何内存泄漏的情况下增加代码的内存使用量?

[英]Is increase in memory usage of my code possible without any memory leak?

There is a C++ code which does some calculations in iterations of a loop. 有一个C ++代码可以在循环迭代中进行一些计算。 When I run my code for a couple of hours, no increase in memory usage is observable. 当我将代码运行几个小时时,看不到内存使用量的增加。 But when I let it run over night, 50 MB increase in memory usage is observed by MS Performance Monitor tool (perfmon.exe) as shown below. 但是,当我让它运行一整夜时,MS Performance Monitor工具(perfmon.exe)会发现内存使用量增加了50 MB,如下所示。 Plots are only for my process not the entire system. 图表仅适用于我的过程,不适用于整个系统。

在此处输入图片说明

Visual Leak Detector cannot detect any memory leak inside the implemented loop. 视觉泄漏检测器无法检测到已实现的循环内的任何内存泄漏。 Is it possible that cause of increase in memory usage is something other than memory leak? 内存使用增加的原因是否可能是内存泄漏以外的原因?

The Visual Leak Detector could be fooled by memory usage patterns which look legitimate while in fact they are not. 可视化泄漏检测器可能会被看起来合理的内存使用模式所迷惑,而实际上却并非如此。 For example, if you keep allocating some things and not only forgetting to free them, but also keeping pointers to them in a list, this looks like normal memory usage as far as any dumb tool can tell. 例如,如果您继续分配一些东西,不仅忘记释放它们,而且将指向它们的指针保存在列表中,就任何傻瓜工具所知,这看起来像是正常的内存使用。

Also, 50MB are not such a huge amount of memory for a desktop application to worry about, and in any case your observations are too limited to be able to draw any conclusions. 而且,50MB的内存不足以供桌面应用程序担心,在任何情况下,您的观察结果都很有限,无法得出任何结论。 It could be that the memory manager of your C++ runtime considers these 50MB peanuts worth sacrificing for efficiency, so it may be choosing not to bother with merging adjacent free blocks to satisfy allocation requests when there is more fresh OS memory available. 可能是C ++运行时的内存管理器认为这些50MB的花生值得牺牲效率,因此当有更多可用的新OS内存可用时,它可能会选择不费心地合并相邻的空闲块来满足分配请求。 In order to better theorize about what is going on you need to show us a more complete graph of the memory allocation of your application over time. 为了更好地对正在发生的事情进行理论化,您需要向我们展示您的应用程序随着时间变化的内存分配的更完整图表。 Is it a continuous straight slope? 它是连续的直坡吗? Is it a slope which turned into a flat line at some point? 它是在某个点变成一条平线的斜坡吗? Does it have a sudden stair step somewhere? 它在某处突然出现了台阶吗? Is it a slope which keeps rising even after you have completely ran out of physical memory and started paging? 即使您完全用尽了物理内存并开始分页之后,斜率是否仍在上升?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM