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. Linked list destruction problem

Linked list destruction problem

Scheduled Pinned Locked Moved C / C++ / MFC
2 Posts 2 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.
  • A Offline
    A Offline
    Andrew Hoole
    wrote on last edited by
    #1

    Hi I have some code that contains a linked list of pointers to a class that itself contains a list of items. These are declared as follows: class CROI : public CObject { DECLARE_DYNCREATE(CROI) . . . CTypedPtrList m_lpOutlines; CTypedPtrList m_lpVertexLists; . . . }; class CVertexList { public: CVertexList(); virtual ~CVertexList(); CList m_lVertices; }; When I need to recreate this list I try and clear the existing list as follows: while(!m_lpVertexLists.IsEmpty()){ pVertexList = m_lpVertexLists.RemoveHead(); delete pVertexList; } Now this crashes sometime either because the pVertexList that it gets is not pointing to valid memory or because the list of objects at the next level down is corrupted at some point (ie a pNext is incorrect). So some how something is corruptting the memory that is used for these lists and I can't figure it out. Does anyone know how I can debug it to find out what is fiddling with the memory. I am using VC++ 6.0 purchased back in 1998 and haven't downloaded any updates that I can remember. Is anyone aware whether they might have been problems with this particular area of VC++. Any help would be much appreciated. Puzzled :confused: Andrew

    T 1 Reply Last reply
    0
    • A Andrew Hoole

      Hi I have some code that contains a linked list of pointers to a class that itself contains a list of items. These are declared as follows: class CROI : public CObject { DECLARE_DYNCREATE(CROI) . . . CTypedPtrList m_lpOutlines; CTypedPtrList m_lpVertexLists; . . . }; class CVertexList { public: CVertexList(); virtual ~CVertexList(); CList m_lVertices; }; When I need to recreate this list I try and clear the existing list as follows: while(!m_lpVertexLists.IsEmpty()){ pVertexList = m_lpVertexLists.RemoveHead(); delete pVertexList; } Now this crashes sometime either because the pVertexList that it gets is not pointing to valid memory or because the list of objects at the next level down is corrupted at some point (ie a pNext is incorrect). So some how something is corruptting the memory that is used for these lists and I can't figure it out. Does anyone know how I can debug it to find out what is fiddling with the memory. I am using VC++ 6.0 purchased back in 1998 and haven't downloaded any updates that I can remember. Is anyone aware whether they might have been problems with this particular area of VC++. Any help would be much appreciated. Puzzled :confused: Andrew

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      I don't believe your problem will disappear when you install latest service pack (SP5). It seems that you're corrupting the heap somewhere. I'd try to reduce the problem - create the sample MFC app with wizard, copy CROI and CVertexList, instantiate one CROI and fill it with multiple lists of vertices. If program will crash, you'll be sure that CROI the source of problems. To automate this kind of debugging you may consider a special tool, like BoundsChecker or Rational Purify. I'm not sure if you can download demo version of BoundsChecker today; evaluation version of Purify can be downloaded from www.rational.com Tomasz Sowinski -- http://www.shooltz.com

      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