Trying to spot a memory leak I have finally arrived at this part of code below.
In it, 'Some operations' corresponds to plotting a geometrical shape with a specific colour and 'More operations' means plotting another shape with a different colour.
When the CreateSolidBrush, SelectObject and DeleteObject functions are commented out the code executes fine without any leaks at all -the total number of GDI objects in the Task Manager stays constant- whereas when they are active, the GDI objects rapidly increase due to the loop. The 'More operations' part involves calling a sub where a different brush is created and destroyed with code similar to that in the calling sequence.
Code:For k = 1 to N
hBrush = CreateSolidBrush(SomeColor)
hOldBrush = SelectObject(MyBackBuffer, hBrush)
‘ Some operations here...
‘ ...
SelectObject MyBackBuffer, hOldBrush
DeleteObject hBrush
‘ More operations here...
‘ ...
Next
