GDI clean up problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi
I am working on WinCe project In which i am loading number of bitmap
objects using BitBlt
function

As per my understanding BitBlt allocates a memory block in the gwes
process heap.


Now my problem is I want to free the memory allocated in the gwes heap
when i dont require the bitmap anymore.


Please can u let me know any method by which i can free this memory and

reuse it again for different bitmap as my memory requirement is very
critical.



Here is the code what I am using to load a bitmap image.
CDC *pDC=this->GetDC();
CBitmap bmp;
CBrush brush;
BITMAP bitmpStruct;
CRect r;
1)HBITMAP bgBMP = LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(m_iBkgBmpRes);
2)if(bgBMP)
{
bmp.Attach(bgBMP);
brush.CreatePatternBrush(&bmp);
GetClientRect(&r);
CBrush *pOldBrush=pDC->SelectObject(&brush);
pDC->FillRect(&r, &brush);
pDC->SelectObject(pOldBrush);
DeleteObject(bmp.Detach());
brush.DeleteObject();
}
ReleaseDC(pDC);

As per my understanding I am properly creating and destroying the GDI
objects.

When I create a brush using CreatePatternBrush The memory allocated is
twice the size of the loaded image( say IMAGE 1)
for eg In my case the image size is 152 k hence the memory allocated is
304 k.
and when i delete the brush object It only recovers 152 k while the
other 152 k is not recovered.

When I load a new bitmap image I face the same problem

Now when I load the same image IMAGE 1 then the CreatePatternBrush
allocates just 152 k and frees it when i call deleteobject.which is
true for every loaded image.

But i am not able to recover the memory leaked while loading every new
image.

As per my Application is fully graphical and the memory requirement are
very critical
I want to able to retrieve the memory allocated by bitmaps which are
not required.which I am not able to do.

I then tried to load the image using BitBlt which is showing me the
same type of problem that is the memory is not recovered.

I read somewhere that GDI takes some time to clean up the unused
memory.Is it that which is causing this leak.

Please let me know what I can do solve this problem.

Shankar

.



Relevant Pages

  • Re: Scaling of data into dc
    ... BitBlt. ... works in logical coordinates, and if there is a mapping mode on the window DC, BitBlt will ... The mapping mode used for the memory DC would do the sizing; the memory DC is a 1:1 size ... many seconds to copy a bitmap ...
    (microsoft.public.vc.mfc)
  • Re: memory leak
    ... ArgumentException on Full Framework) when I have a ton of virtual memory ... "new Bitmap" line. ... Dispose is not a required call - it is optional. ... you are done with those resources. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: One Thing I Noticed - Line Too Long
    ... > in memory plus a further bitmap, or "extra space on the Form wasting ... Turning on autoredraw keeps a copy of what's on the screen in memory. ... are drawing a bitmap to the screen and have the bitmap in memory then you ... > Picture Box and one Command Button. ...
    (microsoft.public.vb.general.discussion)
  • Re: memory leak
    ... Adding GC.Collectcauses the memory to drop, ... Now do you still agree that the GC will cleanup Bitmap objects? ... Dispose is not a required call - it is optional. ... done with those resources. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: How to convert image from Format1bppIndexed to Format24bppRgb?
    ... //image you just need to create a bitmap of the correct size ... > case of conversion to any indexed type you need to understand the pixel ... > Find great Windows Forms articles in Windows Forms Tips and Tricks ... >>> The size of the image file has no bearing on the amount of memory you ...
    (microsoft.public.dotnet.framework.drawing)