C ++内存泄漏 - 解释分析

时间:2015-06-10 09:45:27

标签: c++ memory-leaks

我在下面的c ++代码中有内存泄漏:

void onNewDepthSample(DepthNode node, DepthNode::NewSampleReceivedData data)
{
    INT32 w, h;
    FrameFormat_toResolution(data.captureConfiguration.frameFormat, &w, &h);
    INT32 size = data.depthMap.size();

    int16_t* ptr = new int16_t[size];

        for (int i = 0; i < size; i++){
            ptr[i] = data.depthMap[i];
        }

    depthCB(stringToCsharpString(node.getSerialNumber()), &w, &h, ptr);
    delete[] ptr;   
}

这种方法每秒调用30次。内存泄漏分析:

Function details

Function   DepthsenseDriver!malloc+49 
Source Line    
Allocation type   Heap allocation(s) 
Heap handle   0xcf11e4ac 
Allocation Count   75256 allocation(s) 
Allocation Size   1,22 MBytes 
Leak Probability   100%



Call stack sample 1

Address   0x32335344 
Allocation Time   00:05:00 since tracking started 
Allocation Size   17 Bytes 


Call stack:

DepthsenseDriver!malloc+49   
DepthsenseDriver!operator new+1d
DepthsenseDriver!CreateFileW+96b    
DepthsenseDriver!DepthSense::FunctionHandler<DepthSense::DepthNode,DepthSense::DepthNode::NewSampleReceivedData>::operator()+5d  

我想知道如何解释这种分析。例如,有一个CreateFileW函数调用,但在我的代码中,此函数调用不存在。

我是C ++菜鸟,所以欢迎提出或改进:)

1 个答案:

答案 0 :(得分:0)

使用Deleaker,我发现是导致泄漏的stringToCsharpString方法。