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. Problem using CStrings in a linked list (memory leak)

Problem using CStrings in a linked list (memory leak)

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++data-structuresperformance
5 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.
  • C Offline
    C Offline
    CoffeeAddict19
    wrote on last edited by
    #1

    I'm using a singly linked list of structures. Each structure has 3 cstrings and a pointer in it. The reason I'm using cstrings and not strings is that I'm populating a list box that has to stay persistent. I could use strings but I would have to use .c_str() every time. I wrote the code for the linked list with help from wikepedia and a book and it works, the problem is that I have a memory leak. I still can't find any error in the code though. My question is, are there any special issues with cstrings that would cause a memory leak in this situation? Are their any known problems with their destructors? Here is the function that destroys the linked list if you wouldn't mind checking it:CStringLListElement* CurrentPtr = HeadPtr; CStringLListElement* BackPtr = HeadPtr; while(CurrentPtr != NULL) { BackPtr = CurrentPtr; CurrentPtr = CurrentPtr->ForwardPtr; delete BackPtr; }
    Here is part of the error message from the compiler (I only listed a few lines): Detected memory leaks! Dumping objects -> {299} normal block at 0x010A65A8, 152 bytes long. Data: 48 EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {298} normal block at 0x010A64D0, 152 bytes long. Data: << W 200310 > 3C EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {297} normal block at 0x010A63F8, 152 bytes long. Data: < W 200310 > E4 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {296} normal block at 0x010A6320, 152 bytes long. Data: < W 200310 > F8 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {295} normal block at 0x010A6248, 152 bytes long.The program '[2212] CS_Project.exe: Native' has exited with code 0 (0x0). Thanks for looking at this. I would appreciate any help. :)

    M L P 3 Replies Last reply
    0
    • C CoffeeAddict19

      I'm using a singly linked list of structures. Each structure has 3 cstrings and a pointer in it. The reason I'm using cstrings and not strings is that I'm populating a list box that has to stay persistent. I could use strings but I would have to use .c_str() every time. I wrote the code for the linked list with help from wikepedia and a book and it works, the problem is that I have a memory leak. I still can't find any error in the code though. My question is, are there any special issues with cstrings that would cause a memory leak in this situation? Are their any known problems with their destructors? Here is the function that destroys the linked list if you wouldn't mind checking it:CStringLListElement* CurrentPtr = HeadPtr; CStringLListElement* BackPtr = HeadPtr; while(CurrentPtr != NULL) { BackPtr = CurrentPtr; CurrentPtr = CurrentPtr->ForwardPtr; delete BackPtr; }
      Here is part of the error message from the compiler (I only listed a few lines): Detected memory leaks! Dumping objects -> {299} normal block at 0x010A65A8, 152 bytes long. Data: 48 EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {298} normal block at 0x010A64D0, 152 bytes long. Data: << W 200310 > 3C EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {297} normal block at 0x010A63F8, 152 bytes long. Data: < W 200310 > E4 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {296} normal block at 0x010A6320, 152 bytes long. Data: < W 200310 > F8 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {295} normal block at 0x010A6248, 152 bytes long.The program '[2212] CS_Project.exe: Native' has exited with code 0 (0x0). Thanks for looking at this. I would appreciate any help. :)

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

      I haven't seen a CString leak before. Those unfreed blocks are CString objects for sure? Try adding this to your source files so you can see the file/linenumber where the object was allocated in the leak dump: #ifdef _DEBUG #define new DEBUG_NEW #endif The code looks good to me....I guess it could be shortened a line:

      CStringLListElement* CurrentPtr = HeadPtr;
      while(CurrentPtr != NULL)
      {
      CStringLListElement* BackPtr = CurrentPtr;
      CurrentPtr = CurrentPtr->ForwardPtr;
      delete BackPtr;
      }

      "Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")

      1 Reply Last reply
      0
      • C CoffeeAddict19

        I'm using a singly linked list of structures. Each structure has 3 cstrings and a pointer in it. The reason I'm using cstrings and not strings is that I'm populating a list box that has to stay persistent. I could use strings but I would have to use .c_str() every time. I wrote the code for the linked list with help from wikepedia and a book and it works, the problem is that I have a memory leak. I still can't find any error in the code though. My question is, are there any special issues with cstrings that would cause a memory leak in this situation? Are their any known problems with their destructors? Here is the function that destroys the linked list if you wouldn't mind checking it:CStringLListElement* CurrentPtr = HeadPtr; CStringLListElement* BackPtr = HeadPtr; while(CurrentPtr != NULL) { BackPtr = CurrentPtr; CurrentPtr = CurrentPtr->ForwardPtr; delete BackPtr; }
        Here is part of the error message from the compiler (I only listed a few lines): Detected memory leaks! Dumping objects -> {299} normal block at 0x010A65A8, 152 bytes long. Data: 48 EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {298} normal block at 0x010A64D0, 152 bytes long. Data: << W 200310 > 3C EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {297} normal block at 0x010A63F8, 152 bytes long. Data: < W 200310 > E4 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {296} normal block at 0x010A6320, 152 bytes long. Data: < W 200310 > F8 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {295} normal block at 0x010A6248, 152 bytes long.The program '[2212] CS_Project.exe: Native' has exited with code 0 (0x0). Thanks for looking at this. I would appreciate any help. :)

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        I would be about 99.9999999999999999999999999999999 % sure the leak is in the code you wrote, not in CString.

        led mike

        N 1 Reply Last reply
        0
        • L led mike

          I would be about 99.9999999999999999999999999999999 % sure the leak is in the code you wrote, not in CString.

          led mike

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          led mike wrote:

          I would be about 99.9999999999999999999999999999999 %

          I am 100% percent sure the leak is in his code. :)


          Nibu thomas A Developer Programming tips[^]  My site[^]

          1 Reply Last reply
          0
          • C CoffeeAddict19

            I'm using a singly linked list of structures. Each structure has 3 cstrings and a pointer in it. The reason I'm using cstrings and not strings is that I'm populating a list box that has to stay persistent. I could use strings but I would have to use .c_str() every time. I wrote the code for the linked list with help from wikepedia and a book and it works, the problem is that I have a memory leak. I still can't find any error in the code though. My question is, are there any special issues with cstrings that would cause a memory leak in this situation? Are their any known problems with their destructors? Here is the function that destroys the linked list if you wouldn't mind checking it:CStringLListElement* CurrentPtr = HeadPtr; CStringLListElement* BackPtr = HeadPtr; while(CurrentPtr != NULL) { BackPtr = CurrentPtr; CurrentPtr = CurrentPtr->ForwardPtr; delete BackPtr; }
            Here is part of the error message from the compiler (I only listed a few lines): Detected memory leaks! Dumping objects -> {299} normal block at 0x010A65A8, 152 bytes long. Data: 48 EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {298} normal block at 0x010A64D0, 152 bytes long. Data: << W 200310 > 3C EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {297} normal block at 0x010A63F8, 152 bytes long. Data: < W 200310 > E4 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {296} normal block at 0x010A6320, 152 bytes long. Data: < W 200310 > F8 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {295} normal block at 0x010A6248, 152 bytes long.The program '[2212] CS_Project.exe: Native' has exited with code 0 (0x0). Thanks for looking at this. I would appreciate any help. :)

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #5

            CoffeeAddict19 wrote:

            Detected memory leaks! Dumping objects -> {299} normal block at 0x010A65A8, 152 bytes long. Data: 48 EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {298} normal block at 0x010A64D0, 152 bytes long. Data: << W 200310 > 3C EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {297} normal block at 0x010A63F8, 152 bytes long. Data: < W 200310 > E4 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {296} normal block at 0x010A6320, 152 bytes long. Data: < W 200310 > F8 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {295} normal block at 0x010A6248, 152 bytes long.The program '[2212] CS_Project.exe: Native' has exited with code 0 (0x0).

            You can go to memory leak source, by double clicking these lines.

            Prasad Notifier using ATL | Operator new[],delete[][^]

            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