Black Ice Software
August Developer Newsletter
Volume 11, Issue 8 - August, 2007
The BLACK ICE NEWSLETTER is published by Black Ice Software, LLC. The contents of this newsletter in its entirety are Copyright © 2007 by Black Ice Software, LLC. 292 Route 101, Salzburg Square, Amherst, NH 03031, USA. Black Ice Software, LLC. does hereby give permission to reproduce material contained in this newsletter, provided credit is given to the source, and a copy of the publication that the material appears in is sent to Black Ice Software at the above address. Phone: (603) 673-1019 Fax: (603) 672-4112 sales@blackice.com www.blackice.com

How to Free Allocated Memory for DIBs

If you use the Document Imaging SDK and have a DIB you don’t need anymore, you should free the allocated memory for the DIB, if you don’t, your program has a memory leak. In this case you can just free the allocated memory with the GlobalFree API function.

 

But, if you use the ActiveX controls of the Document Imaging SDK, you can more easily free the allocated memory. The DropDIB method deallocates the memory of the DIB, and most Document Imaging controls have the DropDIB method, for example BiTiff.ocx, BiDib.ocx and BiDisp.ocx.

 

Example how to use the DropDib method in VB .NET

 

Dim hDibNew As Integer

Dim BiDibObj As Object

 

BiDibObj = CreateObject("BIDIB.BIDIBCtrl.1")

 

hDibNew = BiDibObj.RotateDIB90(hDib)

 

If hDibNew <> 0 Then

     ' Free old DIB. We don't need anymore

     BiDibObj.DropDIB(hDib)

End If

 

But if you display a DIB (A) with the BiDisp control, and then you need to display a new DIB (B), you don’t have to call the DropDIB method for A. When the new hDib property of the BiDisp.ocx is set (BiDisp.hDib = B), the BiDisp.ocx frees the previous DIB internally and you don’t have to call the DropDIB method. If you simply want to free the DIB of BiDisp.ocx set the hDib propery to zero (BiDisp.hDib = 0). The BiDisp control will deallocate the memory of the displayed DIB automatically.

 

For example (in VB .NET)

 

Dim hDibNew As Integer

Dim BiDibObj As Object

Dim hDib As Integer = BiDisp.hDib

 

BiDibObj = CreateObject("BIDIB.BIDIBCtrl.1")

 

hDibNew = BiDibObj.RotateDIB90(hDib)

 

If hDibNew <> 0 Then

     ' Do not call DropDib for hDib.

' The BiDisp frees the allocated memory.

     BiDisp.hDib = hDibNew

End If