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 Leaks With CString in vc6.0 in Release mode

Memory Leaks With CString in vc6.0 in Release mode

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsperformanceannouncement
8 Posts 3 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
    Ramasani
    wrote on last edited by
    #1

    I am facing a run time problem with the CString in Release builds in vc6.0 i observed that the memory wont be released for cstring object i checked in the task manager can any one help for this here i posted the code also #include "stdafx.h" #include "afx.h" #include "afxwin.h" #include <windows.h> #include "fixalloc.h" #pragma warning (disable:4786) #pragma warning (disable:4503) #include<list> #include<string> #include<vector> using namespace std; #include <afxtempl.h> void test() { vector<CString> stldmlist; CString a; FILE *fp=fopen("E:\\log1.txt","r"); char str[1000]; while(!feof(fp)) { fscanf(fp,"%s\n",str); a=str; stldmlist.push_back(a); } fclose(fp); AfxMessageBox("Memory"); } UINT32 main(int argc, char* argv[]) { CString obj; AfxMessageBox("Start "); test(); AfxMessageBox("End"); return 1; }

    Hi this Ravinder

    S 1 Reply Last reply
    0
    • R Ramasani

      I am facing a run time problem with the CString in Release builds in vc6.0 i observed that the memory wont be released for cstring object i checked in the task manager can any one help for this here i posted the code also #include "stdafx.h" #include "afx.h" #include "afxwin.h" #include <windows.h> #include "fixalloc.h" #pragma warning (disable:4786) #pragma warning (disable:4503) #include<list> #include<string> #include<vector> using namespace std; #include <afxtempl.h> void test() { vector<CString> stldmlist; CString a; FILE *fp=fopen("E:\\log1.txt","r"); char str[1000]; while(!feof(fp)) { fscanf(fp,"%s\n",str); a=str; stldmlist.push_back(a); } fclose(fp); AfxMessageBox("Memory"); } UINT32 main(int argc, char* argv[]) { CString obj; AfxMessageBox("Start "); test(); AfxMessageBox("End"); return 1; }

      Hi this Ravinder

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Ramasani wrote:

      memory wont be released for cstring object i checked in the task manager

      Given that task manager doesn't tell you if objects released memory or not, I presume you were looking at an process's working set... The behaviour I'm guessing you're talking about (the process's working set rising and not falling after test exits) is to be expected - when you start allocating memory, the C runtime requests large chunks of memory from the Windows memory manager. It will not necessarily bother releasing them when you release objects, as allocating and releasing memory with the Windows memory manager is quite expensive.

      R 1 Reply Last reply
      0
      • S Stuart Dootson

        Ramasani wrote:

        memory wont be released for cstring object i checked in the task manager

        Given that task manager doesn't tell you if objects released memory or not, I presume you were looking at an process's working set... The behaviour I'm guessing you're talking about (the process's working set rising and not falling after test exits) is to be expected - when you start allocating memory, the C runtime requests large chunks of memory from the Windows memory manager. It will not necessarily bother releasing them when you release objects, as allocating and releasing memory with the Windows memory manager is quite expensive.

        R Offline
        R Offline
        Ramasani
        wrote on last edited by
        #3

        if i go for more number of CString calls it returns memory leak errors(no memory) is there any patches available for this? i need very urgent.

        Hi this Ravinder

        S 1 Reply Last reply
        0
        • R Ramasani

          if i go for more number of CString calls it returns memory leak errors(no memory) is there any patches available for this? i need very urgent.

          Hi this Ravinder

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Ramasani wrote:

          memory leak errors(no memory)

          Ummm - 'no memory' does not necessarily imply memory leaks. It could just be that you're allocating a *lot* of memory. How big is this log file you're reading in?

          Ramasani wrote:

          is there any patches available for this?

          Let's think about this - what's more likely to be at fault - MFC/C++ standard libraries or your code/understanding thereof? Mmmm.

          R 1 Reply Last reply
          0
          • S Stuart Dootson

            Ramasani wrote:

            memory leak errors(no memory)

            Ummm - 'no memory' does not necessarily imply memory leaks. It could just be that you're allocating a *lot* of memory. How big is this log file you're reading in?

            Ramasani wrote:

            is there any patches available for this?

            Let's think about this - what's more likely to be at fault - MFC/C++ standard libraries or your code/understanding thereof? Mmmm.

            R Offline
            R Offline
            Ramasani
            wrote on last edited by
            #5

            Actually i am using CString in my application more than 10k times and my apllication will run for days in this cases memory is not releasing thats the problem i have given a sample code only but it is working fine in Debug mode not in release mode ?

            Hi this Ravinder

            S D 2 Replies Last reply
            0
            • R Ramasani

              Actually i am using CString in my application more than 10k times and my apllication will run for days in this cases memory is not releasing thats the problem i have given a sample code only but it is working fine in Debug mode not in release mode ?

              Hi this Ravinder

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Ramasani wrote:

              it is working fine in Debug mode not in release mode

              In what sense? You have not stated a) what you expected to observe when running in release mode and b) what actually did happen. I've run your sample code (admittedly built with VS2003 rather than VC6) and monitored the execution of both debug and release variants with task manager and Process Explorer[^]. In both cases, it behaved exactly as I would expect.

              R 1 Reply Last reply
              0
              • S Stuart Dootson

                Ramasani wrote:

                it is working fine in Debug mode not in release mode

                In what sense? You have not stated a) what you expected to observe when running in release mode and b) what actually did happen. I've run your sample code (admittedly built with VS2003 rather than VC6) and monitored the execution of both debug and release variants with task manager and Process Explorer[^]. In both cases, it behaved exactly as I would expect.

                R Offline
                R Offline
                Ramasani
                wrote on last edited by
                #7

                yeh., Exactly its working in vs2003 and later but not vc6.0 my applications all are in vc6.0. i need patches without changing my application

                Hi this Ravinder

                1 Reply Last reply
                0
                • R Ramasani

                  Actually i am using CString in my application more than 10k times and my apllication will run for days in this cases memory is not releasing thats the problem i have given a sample code only but it is working fine in Debug mode not in release mode ?

                  Hi this Ravinder

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

                  Ramasani wrote:

                  ...my apllication will run for days in this cases memory is not releasing...

                  Are you expecting this to happen automatically? Nowhere in your code are you directly calling new or delete. It seems the problem and the code snippet you've shown are not related.

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

                  "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                  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