View Full Version : Memory Leaks

October 13, 2003, 02:14:16
I'm creating a wrapper DLL for the Imaging Source libraries. Following the code examples that come with the libraries, I have the following:

if (m_pGrabber != 0) {

// Generate a list of all available video devices
pVidCapDevList = m_pGrabber->getAvailableVideoCaptureDevices();

however, there doesn't seem to be a way to delete the pVidCapDevList, and upon termination of the debug session, I see memory leaks in the smart_ptr.

How do I return this memory to the heap?



Stefan Geissler
October 13, 2003, 13:57:25
Hello Ronc,

you can free the memory with following line of code:
pVidCapDevList = NULL;

October 15, 2003, 10:47:36

is it recommended to do this with the other list objects ( pVidNrmList, pVidFmtList, ... ) too, while releasing C-Components ?

Stefan Geissler
October 15, 2003, 13:09:53

If the pointers are used in a scope like a function, then the NULL assign to free memory is not necessary. If you use them as static declarations in your DLL, then you need to assign NULL to them to free the allocated memory explicitly, before calling FreeLibrary().

March 4, 2004, 09:14:40

I encoutered the problems mentionned in these posts, i.e. crash when the "system" tries to free smart_ptr pVidNrmList and pVidFmtList.

I had the lines

but it crashed on these lines !

So what is the solution ?


Stefan Geissler
March 4, 2004, 10:15:31

If your program has crashed, please have a look on the callstack debug window. If there is a function named “_CRTIsValidHeapPointer” listed, then you have use a debug compiled program with release compiled DLL or vice versa.
Please make sure, that your program uses only release compiled DLLs, if it is compiled as release version. And make sure, that you program uses only debug compiled DLLs, if your program is compiled as debug version.
If this not solves you problem, i must have more information about your project: development environment, are you creating a DLL or a standard EXE file etc.