# Release allocated DIB.

This topic is 4352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, my question isn't exactly about DirectX, but about Win32 API. But DX is the most related among these foruns. I have a function which returns a handle to a DIB, which is treated as a HBITMAP.
HBITMAP hbitmap = GetHDIBFromPicture(/* arguments are irrelevant */);


After that, I lock the HBITMAP, get a pointer to DIB and read it.
LPBYTE lpDIB  = (LPBYTE) GlobalLock( hbitmap );
// ...read the DIB and COPY it pixels to another array
GlobalUnlock( hbitmap );


Then, I release the handle through DeleteObject function.
DeleteObject( hbitmap );


But every time I call all those codes above, which all belongs to a procedure, the memory consumed by the process is increased, it keep increasing each time. It seems that the memory allocated by the GetHDIBFromPicture(...) function to create a DIB isn't desalocated by DeleteObject(). I have no further information about that function, because it is poorly documented, but if someone knows any other function to release the allocated DIB, I will thanks. Is it possible to release the DIB allocated by a function?

##### Share on other sites
Not exactly sure what you're trying to do, but there is nothing on google for GetHDIBFromPicture. Maybe use a documented function or create your own. This could have likely gone in General Programming btw, lot of Win32 questions seem to pop up there :)

Also, have you tried not locking it? Not sure exactly why you need too but just for giggles, try commenting out the lock and unlock functions and see if the memory is freed up by DeleteObject.

Also, try "DeleteObject((HGDIOBJ)hbitmap);"

Edit: I seen some code use DestroyObject((HGDIOBJ)hbitmap); You can also try this.

##### Share on other sites
That function isn't documented, because it belongs to a propetary SDK. Anyway, I thought someone could know if is possible to release the memory allocated by that function (or any function, anyway). Because it belongs to my process space.

##### Share on other sites
Quote:
 Original post by biowarriorHello, my question isn't exactly about DirectX, but about Win32 API. But DX is the most related among these foruns.

I'm going to move this over to 'General Programming' as you'll probably get a better response. There isn't a specific Win32 programming forum on this site.

Cheers,
Jack

##### Share on other sites
When you get strange errors it helps a lot if you check error codes.

In particular you cannot call GlobalLock/Unlock on an HBITMAP. Nor can you call DeleteObject on an HGLOBAL (the type that GlobalLock/Unlock work with). The most likely problem is probably that the thing that GetHDIBFromPicture is returning is not actually an HBITMAP and somebody is doing a bogus cast.

Assuming that your data was actually allocated via GlobalAlloc then it should be freed via GlobalFree.

##### Share on other sites

This topic is 4352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628639
• Total Posts
2983972

• 10
• 18
• 20
• 13
• 9