内存泄漏单元测试c ++ [英] memory leak unit test c++

查看:253
本文介绍了内存泄漏单元测试c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚解决了一个内存泄漏在我的应用程序,现在我想写一个单元测试,以确保这不会再发生。

I have just resolved a memory leak in my application and now I want to write a unit test to ensure that this does not happen again.

我正在寻找一种方法来检测当前应用程序(工作集)的内存使用情况,一些功能之前和之后。

I'm look for a way to detect the memory usage of the current application (working set), before and after some functions.

例如:

long mem_used= GetMemUsed(); 
/* Do some work */
/* clean up */

if( mem_used != GetMemUsed() ) {
    Error( "Memory leek" ); 
}



我发现了许多方法来检测整个系统的内存使用情况,不适用于当前应用程序。

I have found plenty of ways to detect the memory usage across the entire system but none for just the current application.

建议,连结,程式码片段?

Suggestions, links, code snippets?

推荐答案

Boost.Test 将在测试运行结束时自动告诉您是否有任何单元测试泄漏了内存。

Boost.Test will automatically tell you at the end of a test run if any of your unit tests leaked memory.

我不知道是否有任何其他C ++单元测试框架提供这种功能。

I don't know if any of the other C++ unit testing frameworks provide this kind of functionality.

这篇关于内存泄漏单元测试c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆