I need to create HBITMAP images very often in a C++ program, and of course I need to delete these bitmap after use. The code is similar to this
HBITMAP hBmp;
while(true) {
hBmp = CreateBitmap(width, height, 1, 8, imageData);
process(hBmp);
DeleteObject(hBmp);
}
I have an infinite cycle in a thread that continuously create an HBITMAP, call a function that use this bitmap, and then delete it. At loop start, I check if the process memory usage is bigger than the previous cycle, and if it is, I print it. Using CreateBitmap() and DeleteObject() result in a small memory leak; the process memory usage increase by 4KB once in a while (sometimes every 10 seconds, sometimes nothing happens for minutes).
I tested it without calling the process function, too, and the problem is still there, so I think is due to the bitmap handling. Furthermore, I've made another test, creating the image outside the infinite loop (so I create it just one time) and processing it infite times in the loop, and no memory leak occures.
NOTE: DeleteObject() always return a value >0 (no errors).
Is it possible that the problem is related to DeleteObject() function? Is there something wrong in creating/deleting bitmap in this way?
TECH NOTES: Windows XP Borland C++ Builder 5