Developers must specifically free up DIBs when they are finished with the DIBs. The Black Ice functions DO NOT do free up memory automatically with the exception to the BiDisp control.
For example, one can load a tiff page into DIB and after printing the page (DIB) one must free the DIB by either using the DropDIB or GlobalFree calls.
To free up a DIB, use the Microsoft API’s GlobalUnlock and GlobalFree functions. These functions will allow developers to both unlock and free the memory.
If one experience that the system is running out of resources or experiences a memory leak in an application then the most likely cause of it is that the hDIB is not freed up correctly. The hDIB object is used to store images and the hDIB object has to be freed once it is no longer required.
Make sure that the hDIB variable is not overwritten before it is freed up. For example, avoid the following: hDIB = RotateDIB(hDIB, 90). This will result in a memory leak since the previous image stored in the hDIB variable was not freed before the rotated image was assigned to hDIB. Use the following code instead:
HDIB hTempDIB = RotateDIB(hDIB, 90);
GlobalFree(hDIB);
hDIB = hTempDIB;
Do not free any of the DIB handles that were assigned to the BiDisp control. BiDisp will free the old handle automatically when you assign a new DIB or the BiDisp control is freed.
Trying to free a DIB handle that has already been freed can result in a crash.