这是我写的一段代码,用gdi+来把jpg转成bmp,但每次执行以后就会多占用2到3m内存无法释放.请问应如何处理
-------------------------------------------------
 HDC  m_hdc = GetDC(hwnd);
 HDC  m_hdcmem = CreateCompatibleDC(m_hdc);
 HWND m_hwnd = hwnd;
      int i =   ReleaseDC(hwnd,m_hdc);
 if(m_hdc == NULL) return;
   GdiplusStartupInput gdiplusStartupInput; 
   ULONG_PTR gdiplusToken; 
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);   Graphics graphics(m_hdcmem);    Image image(ToWChar(strFileName.GetBuffer(strFileName.GetLength()))); 
  
   CLSID clsid; 
   if(GetImageCLSID(L"image/bmp", &clsid)) 
  image.Save(ToWChar(".\\test.bmp"), &clsid, NULL);
  
   HBITMAP hbmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(),".\\test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); 
   BITMAP bm;
   GetObject(hbmp, sizeof(bm), &bm);
   SelectObject(m_hdcmem,hbmp);
  
   DelPointFile("test.bmp",".");-------------------------------------------
注:GdiplusShutedown是在后面处理的.hwnd由外部传入,DelPointFile是用来删除文件的函数

解决方案 »

  1.   

    You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.You can call GdiplusStartup on one thread and call GdiplusShutdown on another thread as long as you delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.Do not call GdiplusStartup or GdiplusShutdown in DllMain or in any function that is called by DllMain. If you want to create a dynamic-link library (DLL) that uses GDI+, you should use one of the following techniques to initialize GDI+:
    Require your clients to call GdiplusStartup before they call the functions in your DLL and to call GdiplusShutdown when they have finished using your DLL. 
    Export your own startup function that calls GdiplusStartup and your own shutdown function that calls GdiplusShutdown. Require your clients to call your startup function before they call other functions in your DLL and to call your shutdown function when they have finished using your DLL. 
    Call GdiplusStartup and GdiplusShutdown in each of your functions that make GDI+ calls.
      

  2.   

    m_hdc , m_hdcmem 没有释放
    release(m_hdc);
    release(m_hdcmem);
      

  3.   

    资源释放问题 
    releaseDC(hdc)..凡是资源 使用后记得释放 ,看次三篇文章 
    http://www.csdn.net/Develop/Read_Article.asp?Id=22766
    http://www.csdn.net/Develop/Read_Article.asp?Id=22767
    http://www.csdn.net/Develop/Read_Article.asp?Id=22768
      

  4.   

    m_hdcmem 没有被释放
    可能调用了多次GdiplusStartup而只调用了一次GdiplusShutdown 
    hbmp 没有删除
    SelectObject返回的对象没有被释放或者重新选择
      

  5.   

    sorry,我忘了说.这段代码是类的一部分.我在类析构时有调用releasedc.我跟踪内存发现是
    Image image(ToWChar(strFileName.GetBuffer(strFileName.GetLength()))); 
        CLSID clsid; 
       if(GetImageCLSID(L"image/bmp", &clsid)) 
      image.Save(ToWChar(".\\test.bmp"), &clsid, NULL);
    这两句耗掉最多内存,且无法恢复.请问怎样释放image的内存?