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
c++performancehelp
7 Posts 5 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.
  • L Offline
    L Offline
    lvantin
    wrote on last edited by
    #1

    I met a problem relating to use CArray in MFC. CArray m_pArr; CMyClass is very simple Class CMyClass { CString m_szName; CString m_szId; long m_i4Age; } allocate memory: for (int i=0;i<1000;i++) { m_Arr.Add(new CMyClass); } destroy memory for (int i = 0;i

    C T S D 4 Replies Last reply
    0
    • L lvantin

      I met a problem relating to use CArray in MFC. CArray m_pArr; CMyClass is very simple Class CMyClass { CString m_szName; CString m_szId; long m_i4Age; } allocate memory: for (int i=0;i<1000;i++) { m_Arr.Add(new CMyClass); } destroy memory for (int i = 0;i

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I'm not familiar with CArray ( I use C++ containers ), but I don't see any problem with this. It would be easier to read your code if you checked 'Do not treat <'s as HTML tags' so it was all visiable though. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

      1 Reply Last reply
      0
      • L lvantin

        I met a problem relating to use CArray in MFC. CArray m_pArr; CMyClass is very simple Class CMyClass { CString m_szName; CString m_szId; long m_i4Age; } allocate memory: for (int i=0;i<1000;i++) { m_Arr.Add(new CMyClass); } destroy memory for (int i = 0;i

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        lvantin wrote: CArray m_pArr; Correct Usage off CArray class is something like this, Ok let take example of your scenario only

        Class CMyClass
        {
        CString m_szName;
        CString m_szId;
        long m_i4Age;
        }

        then you declare CArray something like this CArray<CMyClass,CMyClass&> m_pArr;


        [Vote One Here, Complete my Survey....] Alok Gupta
        visit me at http://www.thisisalok.tk          "I Think Believe this Will Help"

        1 Reply Last reply
        0
        • L lvantin

          I met a problem relating to use CArray in MFC. CArray m_pArr; CMyClass is very simple Class CMyClass { CString m_szName; CString m_szId; long m_i4Age; } allocate memory: for (int i=0;i<1000;i++) { m_Arr.Add(new CMyClass); } destroy memory for (int i = 0;i

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          It seems okay to me. Did you use a profiler to measure, or are you using Task Manager? If it is the latter, there is a good probability that the C++ Runtime Environment is not releasing the memory immediately to the OS. That is perfectly OK. BTW, you don't really need to check if p is not NULL before deleting it, delete(p) itself handles the case where p is NULL. And setting p to NULL has no effect too. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          1 Reply Last reply
          0
          • L lvantin

            I met a problem relating to use CArray in MFC. CArray m_pArr; CMyClass is very simple Class CMyClass { CString m_szName; CString m_szId; long m_i4Age; } allocate memory: for (int i=0;i<1000;i++) { m_Arr.Add(new CMyClass); } destroy memory for (int i = 0;i

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

            lvantin wrote: 2. In release mode, leak!!! memory is allocates for application never decrease... How are you confirming this?


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            L 1 Reply Last reply
            0
            • D David Crow

              lvantin wrote: 2. In release mode, leak!!! memory is allocates for application never decrease... How are you confirming this?


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              L Offline
              L Offline
              lvantin
              wrote on last edited by
              #6

              I used Performance monitor, a tool is supported by Windows, to investigate this. Private Bytes of the application always increases when i used that code to allocate memory and never descreases when release it.

              D 1 Reply Last reply
              0
              • L lvantin

                I used Performance monitor, a tool is supported by Windows, to investigate this. Private Bytes of the application always increases when i used that code to allocate memory and never descreases when release it.

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

                lvantin wrote: Private Bytes of the application always increases when i used that code to allocate memory and never descreases when release it. Which is perfectly normal.


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                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