Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
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.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this