Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Memory Leak

Memory Leak

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsperformancehelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rassul Yunussov
    wrote on last edited by
    #1

    I use CImage class for working with bitmaps and noticed memory leak and can't understand the problem. When i'm trying to change the content of bitmap by accessing the bytes - in different cases i see or not see memory leaks, however the code is same! Here is the code: UINT __cdecl CGNTGDALDlg::GNTClassificationFunction( LPVOID pParam ) { ThreadStruct* pStruct = (ThreadStruct*)pParam; int n = pStruct->pDlg->m_Image.GetHeight(); int m = pStruct->pDlg->m_Image.GetWidth(); int LineLength = pStruct->pDlg->m_Image.GetPitch(); unsigned char* Bitmap = (unsigned char*)pStruct->pDlg->m_Image.GetBits(); Bitmap+=LineLength*pStruct->Offset; if(pStruct->pDlg->m_floatingWindowSize==0) { __declspec(align(16)) float* pInputs =(float*) _aligned_malloc(pStruct->pDlg->m_poDataset->GetRasterCount()*sizeof(float),16); for(int i =pStruct->Offset;iEnd;i++) { for(int j = abs(LineLength%m),l=0;jpDlg->m_poDataset->GetRasterCount();k++) { pInputs[k] = pStruct->pDlg->m_pImageMatrix[k][i][m-l-1]; Norm+=pInputs[k]; } Norm = sqrt(Norm); for(int k = 0;kpDlg->m_poDataset->GetRasterCount();k++) pInputs[k]/=Norm; EnterCriticalSection(&pStruct->pDlg->m_CriticalSection); unsigned int value = pStruct->pDlg->m_pGNTNet->Propagate(pInputs,distance,&pNeuron); LeaveCriticalSection(&pStruct->pDlg->m_CriticalSection); *(Bitmap-LineLength-j-1) = GetRValue(value);//eto krasnii *(Bitmap-LineLength-j-2) = GetGValue(value);//eto zelenii *(Bitmap-LineLength-j-3) = GetBValue(value);//eto sinii } Bitmap+=LineLength; } _aligned_free(pInputs); } else { __declspec(align(16)) float* pInputs =(float*) _aligned_malloc(pStruct->pDlg->m_floatingWindowSize*pStruct->pDlg->m_floatingWindowSize*pStruct->pDlg->m_poDataset->GetRasterCount()*sizeof(float),16); for(int i =pStruct->Offset;iEnd;i++) { if(ipDlg->m_poDataset->GetRasterYSize()-pStruct->pDlg->m_floatingWindowSize) for(int j = abs(LineLength%m),l=0;jpDlg->m_poDataset->GetRasterXSize()-pStruct->pDlg->m_floatingWindowSize) { double distance; CGNTNeuron* pNeuron; int ll = 0; double Norm = 0; for(int k = 0;kpDlg->m_poDataset->GetRasterCount();k++) for(int ii

    M 1 Reply Last reply
    0
    • R Rassul Yunussov

      I use CImage class for working with bitmaps and noticed memory leak and can't understand the problem. When i'm trying to change the content of bitmap by accessing the bytes - in different cases i see or not see memory leaks, however the code is same! Here is the code: UINT __cdecl CGNTGDALDlg::GNTClassificationFunction( LPVOID pParam ) { ThreadStruct* pStruct = (ThreadStruct*)pParam; int n = pStruct->pDlg->m_Image.GetHeight(); int m = pStruct->pDlg->m_Image.GetWidth(); int LineLength = pStruct->pDlg->m_Image.GetPitch(); unsigned char* Bitmap = (unsigned char*)pStruct->pDlg->m_Image.GetBits(); Bitmap+=LineLength*pStruct->Offset; if(pStruct->pDlg->m_floatingWindowSize==0) { __declspec(align(16)) float* pInputs =(float*) _aligned_malloc(pStruct->pDlg->m_poDataset->GetRasterCount()*sizeof(float),16); for(int i =pStruct->Offset;iEnd;i++) { for(int j = abs(LineLength%m),l=0;jpDlg->m_poDataset->GetRasterCount();k++) { pInputs[k] = pStruct->pDlg->m_pImageMatrix[k][i][m-l-1]; Norm+=pInputs[k]; } Norm = sqrt(Norm); for(int k = 0;kpDlg->m_poDataset->GetRasterCount();k++) pInputs[k]/=Norm; EnterCriticalSection(&pStruct->pDlg->m_CriticalSection); unsigned int value = pStruct->pDlg->m_pGNTNet->Propagate(pInputs,distance,&pNeuron); LeaveCriticalSection(&pStruct->pDlg->m_CriticalSection); *(Bitmap-LineLength-j-1) = GetRValue(value);//eto krasnii *(Bitmap-LineLength-j-2) = GetGValue(value);//eto zelenii *(Bitmap-LineLength-j-3) = GetBValue(value);//eto sinii } Bitmap+=LineLength; } _aligned_free(pInputs); } else { __declspec(align(16)) float* pInputs =(float*) _aligned_malloc(pStruct->pDlg->m_floatingWindowSize*pStruct->pDlg->m_floatingWindowSize*pStruct->pDlg->m_poDataset->GetRasterCount()*sizeof(float),16); for(int i =pStruct->Offset;iEnd;i++) { if(ipDlg->m_poDataset->GetRasterYSize()-pStruct->pDlg->m_floatingWindowSize) for(int j = abs(LineLength%m),l=0;jpDlg->m_poDataset->GetRasterXSize()-pStruct->pDlg->m_floatingWindowSize) { double distance; CGNTNeuron* pNeuron; int ll = 0; double Norm = 0; for(int k = 0;kpDlg->m_poDataset->GetRasterCount();k++) for(int ii

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      I'll try to help but I can't read your posted code. Can you wrap it in "pre" tags instead of "code" tags? How do you know there's a leak? How are you checking? Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      R 1 Reply Last reply
      0
      • M Mark Salsbery

        I'll try to help but I can't read your posted code. Can you wrap it in "pre" tags instead of "code" tags? How do you know there's a leak? How are you checking? Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        R Offline
        R Offline
        Rassul Yunussov
        wrote on last edited by
        #3

        Well, i looked in the task manager - when this process is running the momory grows up. Here is code in pre tags

        UINT __cdecl CGNTGDALDlg::GNTClassificationFunction( LPVOID pParam )
        {
        ThreadStruct* pStruct = (ThreadStruct*)pParam;
        int n = pStruct->pDlg->m_Image.GetHeight();
        int m = pStruct->pDlg->m_Image.GetWidth();
        int LineLength = pStruct->pDlg->m_Image.GetPitch();
        unsigned char* Bitmap = (unsigned char*)pStruct->pDlg->m_Image.GetBits();
        Bitmap+=LineLength*pStruct->Offset;
        if(pStruct->pDlg->m_floatingWindowSize==0)
        {
        __declspec(align(16)) float* pInputs =(float*) _aligned_malloc(pStruct->pDlg->m_poDataset->GetRasterCount()*sizeof(float),16);
        for(int i =pStruct->Offset;iEnd;i++)
        {
        for(int j = abs(LineLength%m),l=0;jpDlg->m_poDataset->GetRasterCount();k++)
        {
        pInputs[k] = pStruct->pDlg->m_pImageMatrix[k][i][m-l-1];
        Norm+=pInputs[k];
        }
        Norm = sqrt(Norm);
        for(int k = 0;kpDlg->m_poDataset->GetRasterCount();k++)
        pInputs[k]/=Norm;
        EnterCriticalSection(&pStruct->pDlg->m_CriticalSection);
        unsigned int value = pStruct->pDlg->m_pGNTNet->Propagate(pInputs,distance,&pNeuron);
        LeaveCriticalSection(&pStruct->pDlg->m_CriticalSection);

        					\*(Bitmap-LineLength-j-1) = GetRValue(value);//eto krasnii
        					\*(Bitmap-LineLength-j-2) = GetGValue(value);//eto zelenii
        					\*(Bitmap-LineLength-j-3) = GetBValue(value);//eto sinii
        			}
        			Bitmap+=LineLength;
        		}
        	\_aligned\_free(pInputs);
        }
        else
        {
        	\_\_declspec(align(16)) float\* pInputs =(float\*) \_aligned\_malloc(pStruct->pDlg->m\_floatingWindowSize\*pStruct->pDlg->m\_floatingWindowSize\*pStruct->pDlg->m\_poDataset->GetRasterCount()\*sizeof(float),16);
        	for(int i =pStruct->Offset;iEnd;i++)
        		{
        			if(ipDlg->m\_poDataset->GetRasterYSize()-pStruct->pDlg->m\_floatingWindowSize)
        			for(int j = abs(LineLength%m),l=0;jpDlg->m\_poDataset->GetRasterXSize()-pStruct->pDlg->m\_floatingWindowSize)
        				{
        						double distance;
        						CGNTNeuron\* pNeuron;
        						int ll = 0;
        						double Norm = 0;
        						for(int k = 0;kpDlg->m\_poDataset->GetRasterCount();k++)
        							for(int ii = i;iipDlg->m\_floatingWindowSize;ii++)
        								for(int jj = l;jjpDlg->m\_floatingWindowSize;jj++)
        								{
        									pInputs\[ll++\] = pS
        
        M 1 Reply Last reply
        0
        • R Rassul Yunussov

          Well, i looked in the task manager - when this process is running the momory grows up. Here is code in pre tags

          UINT __cdecl CGNTGDALDlg::GNTClassificationFunction( LPVOID pParam )
          {
          ThreadStruct* pStruct = (ThreadStruct*)pParam;
          int n = pStruct->pDlg->m_Image.GetHeight();
          int m = pStruct->pDlg->m_Image.GetWidth();
          int LineLength = pStruct->pDlg->m_Image.GetPitch();
          unsigned char* Bitmap = (unsigned char*)pStruct->pDlg->m_Image.GetBits();
          Bitmap+=LineLength*pStruct->Offset;
          if(pStruct->pDlg->m_floatingWindowSize==0)
          {
          __declspec(align(16)) float* pInputs =(float*) _aligned_malloc(pStruct->pDlg->m_poDataset->GetRasterCount()*sizeof(float),16);
          for(int i =pStruct->Offset;iEnd;i++)
          {
          for(int j = abs(LineLength%m),l=0;jpDlg->m_poDataset->GetRasterCount();k++)
          {
          pInputs[k] = pStruct->pDlg->m_pImageMatrix[k][i][m-l-1];
          Norm+=pInputs[k];
          }
          Norm = sqrt(Norm);
          for(int k = 0;kpDlg->m_poDataset->GetRasterCount();k++)
          pInputs[k]/=Norm;
          EnterCriticalSection(&pStruct->pDlg->m_CriticalSection);
          unsigned int value = pStruct->pDlg->m_pGNTNet->Propagate(pInputs,distance,&pNeuron);
          LeaveCriticalSection(&pStruct->pDlg->m_CriticalSection);

          					\*(Bitmap-LineLength-j-1) = GetRValue(value);//eto krasnii
          					\*(Bitmap-LineLength-j-2) = GetGValue(value);//eto zelenii
          					\*(Bitmap-LineLength-j-3) = GetBValue(value);//eto sinii
          			}
          			Bitmap+=LineLength;
          		}
          	\_aligned\_free(pInputs);
          }
          else
          {
          	\_\_declspec(align(16)) float\* pInputs =(float\*) \_aligned\_malloc(pStruct->pDlg->m\_floatingWindowSize\*pStruct->pDlg->m\_floatingWindowSize\*pStruct->pDlg->m\_poDataset->GetRasterCount()\*sizeof(float),16);
          	for(int i =pStruct->Offset;iEnd;i++)
          		{
          			if(ipDlg->m\_poDataset->GetRasterYSize()-pStruct->pDlg->m\_floatingWindowSize)
          			for(int j = abs(LineLength%m),l=0;jpDlg->m\_poDataset->GetRasterXSize()-pStruct->pDlg->m\_floatingWindowSize)
          				{
          						double distance;
          						CGNTNeuron\* pNeuron;
          						int ll = 0;
          						double Norm = 0;
          						for(int k = 0;kpDlg->m\_poDataset->GetRasterCount();k++)
          							for(int ii = i;iipDlg->m\_floatingWindowSize;ii++)
          								for(int jj = l;jjpDlg->m\_floatingWindowSize;jj++)
          								{
          									pInputs\[ll++\] = pS
          
          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          As long as you are freeing memory you allocate you should be fine. The task manager isn't always a great leak detector. Memory allocated for your process may be marked as available to the application but not freed until it's necessary - for performance. Trust your code :) The debug C runtime (CRT) will show leaks at runtime for malloc, _aligned_malloc, new, etc. Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          R 1 Reply Last reply
          0
          • M Mark Salsbery

            As long as you are freeing memory you allocate you should be fine. The task manager isn't always a great leak detector. Memory allocated for your process may be marked as available to the application but not freed until it's necessary - for performance. Trust your code :) The debug C runtime (CRT) will show leaks at runtime for malloc, _aligned_malloc, new, etc. Mark

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            R Offline
            R Offline
            Rassul Yunussov
            wrote on last edited by
            #5

            Ok! Thank You very much for participating.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups