如何处理C ++类的构造函数中的内存泄漏? [英] How to handle memory leak in constructor of a C++ class?
问题描述
Hallo亲爱的,
您能指导我,如何以最简单,最好的方式处理侧面构造器中的内存泄漏.
我想使用在线提供的任何免费的Memory Leak Detector工具.我在网上搜索过,但不幸的是,我却没有获得任何简单易用的教程.因此,请尽快分享这些知识.
请帮助我asps.
Hallo dear,
Can you please guide me, how to handle memory leak in side CONSTRUCTOR in a very simplest & best way.
I want to use any free Memory-Leak detector TOOL available online. I''hv searched online but unfortunately i didn''t get any good easy Tutorial for the same. So please share this knowledge also soon.
Kindly please help me asps.
推荐答案
您可能想看一下这篇文章:
内存泄漏检测 [ http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx [ ^ ]
最好的问候
Espen Harlinn
You may want to take a look at this article:
Memory Leak Detection[^]
Be sure to read up on the features provided with Visual C++:
http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx[^]
Best regards
Espen Harlinn
您怎么知道您有内存泄漏?
如果您具有类(和构造函数)代码,那么应该很容易跟踪代码并查明内存分配,更重要的是,不存在的内存解除分配.
如果将类放在一个简单的项目中并在堆栈上创建该类的实例并正常退出进程,它会泄漏吗? (即调试器是否在调试会话结束时列出了内存泄漏?)
例如:
How do you know you have a memory leak ?
If you have the class (and the constructor) code then it should be easy to trace the code and pin-point the memory allocations or more importantly, the non-existant memory de-allocation.
If you put the class in a simple project and create an instance of the class on the stack and exit the process normally, does it leak ? (i.e. is the debugger listing memory leak at the end of the debuggin session?)
for example :
class YouClass;
int main(...)
{
YourClass yourClass;
return 1;
}
会泄漏吗?
如果使用new
在堆上分配,是否使用delete
删除内存?
does that leak ?
if you allocate on the heap with new
, do you delete the memory with delete
?
class YouClass;
int main(...)
{
YourClass* yourClass = NULL;
yourClass = new YourClass;
delete yourClass;
yourClass = NULL;
return 1;
}
如果简单程序泄漏,请检查类和轨道分配,以及取消分配,尤其是在destructor
中.
最多
If the simple program leaks, check the class and track allocation, and also de-allocation, especially in the destructor
.
Max.
http://www.codeproject.com/search.aspx?q=Memory+leak&x=0&y=0&sbo=kw [
这篇关于如何处理C ++类的构造函数中的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!