C 内存在Windows 7上泄漏
C++ Memory leaks on Windows 7
我正在编写一个程序(C ,mingw 32位),以使用openCV函数批量处理图像,使用gengelscript作为脚本语言。截至目前,我的软件有一些内存泄漏,这些内存泄漏很快(图像为100-200 MB,我一次都在处理数千个),但是我遇到了Windows似乎没有的图像释放我的程序使用的内存,直到重新启动为止。
如果我在大量图像上运行它,它将运行一段时间,最终将OpenCV抛出一个例外,说它不在记忆中。那时,我关闭了程序,任务管理器的物理内存仪表下降到我开始之前的位置。但这是捕获量 - 每次我尝试再次运行程序时,它将立即失败,将内存分配给OpenCV,直到我重新启动计算机,此时,它将再次适用于几百个图像。<<<<<<<</p>
Windows是否可以保持这种内存?还是有另一个原因为什么Windows无法将内存分配给我的程序,直到重新启动?这对我没有意义。
编辑:我正在运行此程序的计算机是Windows 7 64位,带有32 GB的RAM。通常,该程序在退出之前以超过1 GB的RAM降低。
编辑2:我也使用免费图像加载图像,我忘了提及这一点。这是我的处理代码的基础:
//load bitmap with FreeImage
FIBITMAP *bitmap = NULL;
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
fif = FreeImage_GetFileType(filename.c_str(), 0);
bitmap = FreeImage_Load(fif, filename.c_str(), 0);
if (!bitmap) {
LogString("ScriptEngine: input file is not readable.");
processingFile = false;
return false;
}
//convert FreeImage bitmap to my custom wrapper for OpenCV::Mat
ScriptImage img;
img.image = fi2cv(bitmap);
FreeImage_Unload(bitmap);
try {
//this executes the AngelScript code
r = ctx->Execute();
} catch(std::exception e) {
std::cout << "Exception in " << __FILE__ << ", line " << __LINE__ << ", " << __FUNCTION__ << ": " << e.what() << std::endl;
}
try {
engine->GarbageCollect(asGC_FULL_CYCLE | asGC_DESTROY_GARBAGE);
} catch (std::exception e) {
std::cout << "Exception in " << __FILE__ << ", line " << __LINE__ << ", " << __FUNCTION__ << ": " << e.what() << std::endl;
}
您可以看到,唯一的指针是释放的fibitMap。
您很有可能在此行上制作图像数据的副本:
img.image = fi2cv(bitmap);
由于您之后要立即释放位图,因此该数据必须在免费之后持续。
检查是否有用于ScriptiMage对象的资源发布。
相关文章:
- valgrind-hellgrind与泄漏检查的结果不同
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux for Windows上编译C++代码时出错
- 在Windows上用C++裁剪HBITMAP
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 从构造函数抛出异常时如何克服内存泄漏
- 通用 Windows 平台上的内存泄漏检测
- C 控制台程序中的内存泄漏调用Windows API
- C 内存在Windows 7上泄漏
- Windows开发:如何确定我的应用程序是否正在泄漏内存
- 检测可视C++ (Windows) 中的内存泄漏
- Windows 7清理C++内存泄漏
- 在Windows上重复数百次后,C++屏幕捕获失败:内存泄漏
- 检测c++ Windows应用程序中的内存泄漏
- Windows Service (CodeGear c++ XE5)内存泄漏
- 如何在Windows上检测QtCreator中的内存泄漏
- 免费应用程序检查内存泄漏在Windows x64