Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Flush Memory Usage?

Hello!  I have been adding to this little LAN Chat app I wrote...  today I was checking the Processes in Taskman and noticed that the memory this program uses increases little by little as it runs...  is there some code I can add that will "flush" the memory and keep usage to a minimum without messing with the program too much.  Code is below:

#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[])
{
  std::string target;
  std::string GetStarted = "net send ";
  std::string spacer = " ";
  std::string messg;
 
 
  cout << "Welcome to LAN Messenger 1.0 beta 3.\n";
  cout << "Enter /h in any field at anytime for help.\n";
  cout << "\n";
  system("Pause");
  goto MainTitle;
 
MainTitle:
  system("CLS");
  cout << "\n";
  cout << "|    __   __       __  |__   __  _|_  \n";
  cout << "|_, (__( |  )     (___ |  ) (__(  |_, \n";
  cout << "                                v1.0 b3\n";
  goto MainMenu;
 
MainMenu:
  cout << "\n";
  cout << "\n";
  cout << "               OPTIONS: \n";
  cout << "\n";
  cout << "            CTRL+C -> Chat\n";
  cout << "            CTRL+H -> Help\n";
  cout << "            CTRL+X -> Exit\n";
  char ch;
  while (ch = getch())
  {
  if(ch == 0x08)
      {
            goto Help;
      }
  if(ch == 0x18)
    {
        cout << "Have a nice day";
        return 0;
    }
  if(ch == 0x03)
    {
        goto Begin;
    }
                  
  }                                
 

Begin:
  system("CLS");
  cout << "Target: ";
  cin >> target;
  if(target == "/h" || target == "/H")
  {
      system("CLS");
      goto Help;
  }
  if(target == "/m" || target == "/M")
  {
        system("CLS");
        goto MainMenu;
  }
 
  if(target == "//")
  {
      system("CLS");
      cout << "\n";
      cout << "Connection terminated.\n";
      cout << "\n";
      system("Pause");
      return 0;
  }        
 
 
  do
  {
      cout << "Connection to " << target << "\n";
      cout << "Message: ";
      getline(cin,messg);
     
      if(messg == "//")
      {
          system("CLS");
          cout << "\n";
          cout << "Connection to " << target << " terminated!\n";
          cout << "\n";
          system("Pause");
      }  
     
      if(messg == "/")
      {
          goto Begin;
      }    
     
      if(messg == "/h" || messg == "/H")
      {
          system("CLS");
          goto Help;
      }
        if(messg == "/m" || messg == "/M")
        {
              system("CLS");
              goto MainMenu;
        }
               
      std::string command = GetStarted + target + spacer + messg;
      system(command.c_str());
      system("CLS");
  }while (messg != "//");  
 
Help:
  system("CLS");
  cout << "*Target* <- Enter target users network name, or computer name.\n";
  cout << "*Message* <- Enter your message.\n";
  cout << "To change target users, enter / in the message field.\n";
  cout << "To view help file, enter /h in the message field.\n";
  cout << "To return to Main Menu enter /m in any field.\n";
  cout << "To exit, enter // in the message field.\n";
  cout << "\n";
  system("Pause");
  goto Begin;


  return 0;    

}


Thanks in advance!

Regards,
Tony
0
fattumsdad
Asked:
fattumsdad
2 Solutions
 
brettmjohnsonCommented:
You can use a debugging memory allocation library to help you isolate
memory leaks.

http://dmalloc.com

0
 
jkrCommented:
There's no reason for any 'malicious' increase of memory usage in your program. Which field in the task manager are you watching? If you mean the 'maximum memory load', that's just a high-water mark of the highest memory consumption during the runtime of your program and will never decrease. The value of interest actually is the 'virtual memory' field.
0
 
fattumsdadAuthor Commented:
JKR,

I go to the Task Manager and click on Processes, I'm looking under the "Mem Usage" column.  Is there a way I can bring that number (about 722K) down?  :)

Regards,
Tony
0
 
IndrawatiCommented:
Hi

Just note that the Mem Usage colum in the task manager does not 100% reflect the amount of memory you app consumes. It's explained in this article:

http://www.codeproject.com/system/howbig.asp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now