VBfx / Tile tutorial / Step 6

Releasing memory

This short function releases all memory reserved by the specified bitmap. Note again that we have to differ between loaded and created surfaces, this is because we have to release different objects in each case:

Public Sub ReleaseBitmap( iBitmapInfo as tBitmapInfo )
    With iBitmapInfo
        'Select the original object for use
        SelectObject .DC, .OriginalObject
        If .MemoryDC Then
            'Release created bitmap
            DeleteObject .CompatibleBitmap
            'Release loaded picture
            DeleteObject .PictureDisp
        End If
        'Release the DC
        DeleteDC .DC
    End With
End Sub

You can say that DC and OriginalObject are shared by both kinds of surfaces, however this is again API stuff you don't have to know exactly.