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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Mem Usage keeps increasing

Mem Usage keeps increasing

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
11 Posts 4 Posters 1 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.
  • F FISH786

    Can someone please help me as to why the mem usage in task manager is increasing when I run this loop. What can I change for it not to do that?

    do
    	{
    		for (x=1;x<27;x++)
    		{
    			m\_bmpCtrl.RedrawWindow();
    			strFileName = "F:\\\\Pictures\\\\Pic";
    			\_itoa\_s(x,Temp,sizeof(Temp),10);
    			strFileName += Temp;
    			strFileName += ".bmp";
    			m\_bmpCtrl.LoadFile(strFileName);
    			m\_bmpCtrl.RedrawWindow();
    			ProcessMessages();
    			::Sleep(1500);
    			ProcessMessages();
    			y++;
    		}
    	}while (bDoLoop);
    

    Thanks a million.

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    Why would you expect it to do otherwise? See here for why Task Manager is not a good measure of a program's memory consumption. As far as cleanup goes, you can replace

    strFileName = "F:\\Pictures\\Pic";
    _itoa_s(x,Temp,sizeof(Temp),10);
    strFileName += Temp;
    strFileName += ".bmp";

    with

    strFileName.Format("F:\\Pictures\\Pic%d.bmp", x);

    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    F 1 Reply Last reply
    0
    • D David Crow

      Why would you expect it to do otherwise? See here for why Task Manager is not a good measure of a program's memory consumption. As far as cleanup goes, you can replace

      strFileName = "F:\\Pictures\\Pic";
      _itoa_s(x,Temp,sizeof(Temp),10);
      strFileName += Temp;
      strFileName += ".bmp";

      with

      strFileName.Format("F:\\Pictures\\Pic%d.bmp", x);

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      F Offline
      F Offline
      FISH786
      wrote on last edited by
      #3

      Thank you. I guess the code is fine as is. I really wasn't checking on the mem usage in task manager but was looking for something there and noticed the usage kept increasing.

      1 Reply Last reply
      0
      • F FISH786

        Can someone please help me as to why the mem usage in task manager is increasing when I run this loop. What can I change for it not to do that?

        do
        	{
        		for (x=1;x<27;x++)
        		{
        			m\_bmpCtrl.RedrawWindow();
        			strFileName = "F:\\\\Pictures\\\\Pic";
        			\_itoa\_s(x,Temp,sizeof(Temp),10);
        			strFileName += Temp;
        			strFileName += ".bmp";
        			m\_bmpCtrl.LoadFile(strFileName);
        			m\_bmpCtrl.RedrawWindow();
        			ProcessMessages();
        			::Sleep(1500);
        			ProcessMessages();
        			y++;
        		}
        	}while (bDoLoop);
        

        Thanks a million.

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #4

        cleanup the loop call m_bmpCtrl.LoadFile(strFileName); outside of the do{} loop :doh:

        Press F1 for help or google it. Greetings from Germany

        F 1 Reply Last reply
        0
        • K KarstenK

          cleanup the loop call m_bmpCtrl.LoadFile(strFileName); outside of the do{} loop :doh:

          Press F1 for help or google it. Greetings from Germany

          F Offline
          F Offline
          FISH786
          wrote on last edited by
          #5

          KarstenK wrote:

          outside of the do{} loop

          :confused: How am I supposed to change the strFileName and load different files inside the loop?

          S 1 Reply Last reply
          0
          • F FISH786

            KarstenK wrote:

            outside of the do{} loop

            :confused: How am I supposed to change the strFileName and load different files inside the loop?

            S Offline
            S Offline
            Sarath C
            wrote on last edited by
            #6

            If you need to load a new file, the resources has to be properly released if it's anymore used. So please release the buffers and handles associated with LoadFile operation. I think the other part of the code is just fine.

            -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

            My blog - Sharing My Thoughts

            F 3 Replies Last reply
            0
            • S Sarath C

              If you need to load a new file, the resources has to be properly released if it's anymore used. So please release the buffers and handles associated with LoadFile operation. I think the other part of the code is just fine.

              -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

              My blog - Sharing My Thoughts

              F Offline
              F Offline
              FISH786
              wrote on last edited by
              #7

              Thank you.

              1 Reply Last reply
              0
              • S Sarath C

                If you need to load a new file, the resources has to be properly released if it's anymore used. So please release the buffers and handles associated with LoadFile operation. I think the other part of the code is just fine.

                -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

                My blog - Sharing My Thoughts

                F Offline
                F Offline
                FISH786
                wrote on last edited by
                #8

                I used the following sample code to do it. I am not sure what I am looking for in order to release the handles. Thanks for you help in advance. http://www.ucancode.net/Visual_C_MFC_Example/VC-Control-Load-View-Bitmap-File.htm[^]

                1 Reply Last reply
                0
                • S Sarath C

                  If you need to load a new file, the resources has to be properly released if it's anymore used. So please release the buffers and handles associated with LoadFile operation. I think the other part of the code is just fine.

                  -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

                  My blog - Sharing My Thoughts

                  F Offline
                  F Offline
                  FISH786
                  wrote on last edited by
                  #9

                  I have put this and now the Memory is not as bad but it keeps increasing.

                  HBITMAP test = m_bmpCtrl.hBitmap;
                  if (test)
                  {
                  DeleteObject(test);

                  		}
                  

                  Can someone please help

                  S 1 Reply Last reply
                  0
                  • F FISH786

                    I have put this and now the Memory is not as bad but it keeps increasing.

                    HBITMAP test = m_bmpCtrl.hBitmap;
                    if (test)
                    {
                    DeleteObject(test);

                    		}
                    

                    Can someone please help

                    S Offline
                    S Offline
                    Sarath C
                    wrote on last edited by
                    #10

                    What's the type of m_bmpCtrl variable? There will be direct functions exposed in the class to clear the attached resources also the way you released the resources is quite wrong. if you're explicity releasing the resource, it's your responsibility to assign it as NULL. Otherwise the next call this function may crash, as you've released the previously and the m_bmpCtrl.hBitmap still holds an junk(invalid) handle. also why it's necessary to create a temporary variable? the following way is straight forward no?

                    if (m_bmpCtrl.hBitmap)
                    {
                    DeleteObject(m_bmpCtrl.hBitmap);
                    m_bmpCtrl.hBitmap = NULL;
                    }

                    -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

                    My blog - Sharing My Thoughts

                    F 1 Reply Last reply
                    0
                    • S Sarath C

                      What's the type of m_bmpCtrl variable? There will be direct functions exposed in the class to clear the attached resources also the way you released the resources is quite wrong. if you're explicity releasing the resource, it's your responsibility to assign it as NULL. Otherwise the next call this function may crash, as you've released the previously and the m_bmpCtrl.hBitmap still holds an junk(invalid) handle. also why it's necessary to create a temporary variable? the following way is straight forward no?

                      if (m_bmpCtrl.hBitmap)
                      {
                      DeleteObject(m_bmpCtrl.hBitmap);
                      m_bmpCtrl.hBitmap = NULL;
                      }

                      -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

                      My blog - Sharing My Thoughts

                      F Offline
                      F Offline
                      FISH786
                      wrote on last edited by
                      #11

                      Thank you. That has partly solved it. Yes there was no point creating extra variable. The m_bmpCtrl is of CBitmapCtrl class. I am new at this and am learning. Thanks for all your help It's greatly appreciated.

                      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