Ask Your Question
0

Why does this code snip produce memory leaks ?

asked 2012-11-01 23:18:38 -0600

kalenko gravatar image

updated 2012-11-02 04:12:17 -0600

Hi everybody,

I have a small program which uses Opencv library. And I do not know why it produce memory leaks. Here is the all program code:

#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#ifdef _DEBUG   
    #ifndef DBG_NEW      
        #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )      
        #define new DBG_NEW   
#endif
#endif  // _DEBUG
class C
{
public: 
        C();
        ~C();
        void Test();
};
void C::Test()
{
    IplImage * image = cvCreateImage(cvSize(640, 680), 8, 3);
    cvReleaseImage(&image);
    image = NULL;
}
int main(int argc, char** argv)
{
    _CrtDumpMemoryLeaks();
}


And here is the Output window:

'CVSample.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'CVSample.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
Detected memory leaks!
Dumping objects ->
{135} normal block at 0x00454B18, 29 bytes long.
 Data: <    (KE /KE     > 00 00 00 00 28 4B 45 00 2F 4B 45 00 00 00 00 00 
{134} normal block at 0x00454AA0, 57 bytes long.
 Data: <    (       (JE > 00 00 00 00 28 00 00 00 00 00 00 00 28 4A 45 00 
{133} normal block at 0x00454A28, 54 bytes long.
 Data: <    (    JE  IE > 00 00 00 00 28 00 00 00 A0 4A 45 00 B0 49 45 00 
{132} normal block at 0x004549B0, 53 bytes long.
 Data: <    (   (JE 0IE > 00 00 00 00 28 00 00 00 28 4A 45 00 30 49 45 00 
{131} normal block at 0x00454930, 61 bytes long.
 Data: <    (    IE  HE > 00 00 00 00 28 00 00 00 B0 49 45 00 B8 48 45 00 
{130} normal block at 0x004548B8, 53 bytes long.
 Data: <    (   0IE 8HE > 00 00 00 00 28 00 00 00 30 49 45 00 38 48 45 00 
{129} normal block at 0x00454838, 61 bytes long.
 Data: <    (    HE  GE > 00 00 00 00 28 00 00 00 B8 48 45 00 C0 47 45 00 
{128} normal block at 0x004547C0, 56 bytes long.
 Data: <    (   8HE     > 00 00 00 00 28 00 00 00 38 48 45 00 00 00 00 00 
Object dump complete.
The program '[2620] CVSample.exe: Native' has exited with code 0 (0x0).

I do not know why ? please help ?

edit retag flag offensive close merge delete

Comments

1

Please, try to create C object in main function and call Test method in cycle. In task manager you can see a memory, consumed by your program. Is this amount increasing with time?

Daniil Osokin gravatar imageDaniil Osokin ( 2012-11-02 02:14:25 -0600 )edit
2

These leaks are spurious: the program does nothing, and they only amount to a few hundred bytes, once-off, before the call to main(). The only use of this list is to compare against the leaks that show up just before the program terminates so that you can work out which of them are occurring in your own code.

worst guy ever gravatar imageworst guy ever ( 2012-11-02 04:54:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2012-11-05 20:07:06 -0600

kalenko gravatar image

@worst guy ever: Do you mean that the CRT debug reports are wrong ?

edit flag offensive delete link more

Comments

1

No, just that they are unimportant. Some memory is being allocated on the heap during initialisation, and _CrtDumpMemoryLeaks() just gives you a summary of the heap. A few stray entries is perfectly OK and normal and you shouldn't spend another minute worrying about it.

worst guy ever gravatar imageworst guy ever ( 2012-11-12 00:18:11 -0600 )edit

Question Tools

Stats

Asked: 2012-11-01 23:18:38 -0600

Seen: 1,317 times

Last updated: Nov 05 '12