Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6791241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:49:21+00:00 2026-05-26T17:49:21+00:00

In my application I am getting DC using GetDC and I am also releasing

  • 0

In my application I am getting DC using GetDC and I am also releasing that DC using ReleaseDC.

But when I am profiling my application with VTune, it is showing a GDIResource Leak at GetDC.

m_hdc = ::GetDC(hWndDisplay[frameIndex]);
::SetStretchBltMode(m_hdc,STRETCH_DELETESCANS);
::StretchDIBits(m_hdc,0,0,IMAGE_WIDTH,IMAGE_HEIGHT,0,0,imageWidth,imageHeight,rgbavpg,pTempBmpInfo,DIB_RGB_COLORS,SRCCOPY);
::ReleaseDC(hWndDisplay[frameIndex],m_hdc);

The following is relevant code: m_hdc id defined globally as HDC m_hdc;

void Display(unsigned char *rgbavpg,unsigned long imageSize, unsigned int imageWidth, unsigned int imageHeight, unsigned int frameIndex)
{

PBITMAPINFO pTempBmpInfo = NULL;
DWORD timespan;
int temp;

if ((IMAGE_WIDTH==imageWidth)&&(IMAGE_HEIGHT==imageHeight))
{
    frameNum++ ;
}
timespan = 1000/15;
DWORD diff = GetTickCount() - tickes[frameIndex];//lvm4;
tickes[frameIndex]=GetTickCount();
if (g_threadMarkedForStop[frameIndex] == TRUE ) 
{        
    return;
}
if(diff < timespan)
    { 
            Sleep(diff);
    }
if (FALSE == ::IsWindow(hWndDisplay[frameIndex])) 
{
    g_threadMarkedForStop[frameIndex] = TRUE
    return;
}

pTempBmpInfo = &m_bmpinfo[frameIndex];
if(pTempBmpInfo != NULL)
{
    pTempBmpInfo->bmiHeader.biWidth= imageWidth ;
    pTempBmpInfo->bmiHeader.biHeight= imageHeight;
}
else 
{
    g_threadMarkedForStop[frameIndex] = TRUE;

    return;
}
m_hdc = ::GetDC(hWndDisplay[frameIndex]);
     ::SetStretchBltMode(m_hdc,STRETCH_DELETESCANS);

if (true == fullscreen)                ::StretchDIBits(m_hdc,0,0,510,320,0,0,imageWidth,imageHeight,rgbavpg,pTempBmpInfo,DIB_RGB_COLORS,SRCCOPY);
else
{       ::StretchDIBits(m_hdc,0,0,IMAGE_WIDTH,IMAGE_HEIGHT,0,0,imageWidth,imageHeight,rgbavpg,pTempBmpInfo,DIB_RGB_COLORS,SRCCOPY);
    //::SetDIBitsToDevice(m_hdc,0,0,IMAGE_WIDTH,IMAGE_HEIGHT,0,0,0,imageHeight,rgbavpg,pTempBmpInfo,DIB_RGB_COLORS);
}
::ReleaseDC(hWndDisplay[frameIndex],m_hdc);
}

Please help me to solve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:49:22+00:00Added an answer on May 26, 2026 at 5:49 pm

    Despite using a member variable m_hdc and not using a local variable this code by itself looks good.

    Do you see VTune marking that leak every time or only sometimes?

    When I see your call to IsWindow() and the variable name g_threadMarkedForStop I wonder if you are doing multithreading. Could it be that you sometimes destroy the window while being between GetDC and ReleaseDC?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application i am getting recieved messages by using brodcast reacevers. but i
I'm developing a flash application that is getting information from a remote server using
Anybody tried here using Getting Real(37Signals) approach to develop windows application? (C#/.NET). Or simply
I'm using the ProgressBar control in a WPF application and I'm getting this old,
I am just getting started creating an AJAX application using server side push. I
I'm getting in trouble. I'm trying to emulate the call Application.Run using Application.DoEvents... this
In one of our application im getting an exception that i can not seem
So I am writing an application using ajax getting from a xml based api.
I wrote a flex application that get the host string from the browser using
I have a web application that using Struts + Spring + Hibernate . In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.