Memory leaks detected by SmartCheck



What types of memory leaks can SmartCheck detect?


SmartCheck tracks memory and resource allocations specifically as they pertain to the Windows API and to components written in languages such as C or C . This specific type of tracking does not apply to programs or components written in Visual Basic.

o Interface leak

o Memory leak

o Resource leak

If a program includes C/C components that have been instrumented with BoundsChecker, version 5.0, FinalCheck, these errors will also be detected:

o Memory leaked due to free

o Memory leaked due to re-assignment

o Memory leaked leaving scope

Any program that uses dynamic allocation of memory is prone to leave some memory allocated when the program finishes. In this instance SmartCheck may report that "A block of memory was allocated and never freed". See sample source code below.

Note: If you are not seeing source code for the leak, then it is likely that the allocating module does not have debug information. This occurs mostly with third party packages or system code. However, you are provided with the address, which can be used to determine the source line where the memory was allocated.

Visual Basic Sample Code

Sub MemoryLeak()

'Allocates space for 1000 integers, but forgets to free it

Dim lGMem As Long

lGMem = GlobalAlloc(GMEM_FIXED, 4000)

'Take some action on the memory

End Sub


The recommended action is to free all memory the program allocates. The source pane displays the line of code where the memory was allocated. You should then determine where the memory should be freed and free it. Memory leaks lead to bad performance and eventual program crashes. To correct the sample code, make a call to free.

'Should have this code to free it

Dim lReturnCode as Long

lReturnCode= GlobalFree(lGMem)

Old KB# 11822
Comment List
Related Discussions