Release allocated DIB.

Started by
3 comments, last by Anon Mike 18 years, 3 months ago
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?
guilherme
Advertisement
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.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

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.

guilherme
Quote:Original post by biowarrior
Hello, 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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
-Mike

This topic is closed to new replies.

Advertisement