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. Cleaning up memory

Cleaning up memory

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestionc++game-devperformance
3 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.
  • M Offline
    M Offline
    mdykstra
    wrote on last edited by
    #1

    Hi, I have implemented a game that adds nodes to a list; in essense it is creating a tree. When I add a node to the tree, I use malloc to create memory for the node and push it onto a stack. I then pop it from the stack and do a check. If the check passes I push it back onto the stack, if it fails, I want to delete the node so I use free() to free the memory that was created for it. What is happening when you look at the Task Manger in Windows (XP), it shows the memory being allocated and freed for the application, but when you look at the field called "Commit Charge" within Task Manager, it shows a constant rise in the amount of virtual memeory being used. This continues to grow until the program ends with a memory allocation error. My question relates to resources/links/recommendations on how to better handle memory within a C++ program. I am using Microsoft VC++, version 6.0. I've looked through the code for memory leaks, but it it appears to do as it should; allocating and releasing memory in the proper order. Since it appears that memory leaks is the cause, I am looking for links or recommendations on how to find these leaks. Any recommendations or resources would be greatly appreciated. Thanks in advance. Martin

    D J 2 Replies Last reply
    0
    • M mdykstra

      Hi, I have implemented a game that adds nodes to a list; in essense it is creating a tree. When I add a node to the tree, I use malloc to create memory for the node and push it onto a stack. I then pop it from the stack and do a check. If the check passes I push it back onto the stack, if it fails, I want to delete the node so I use free() to free the memory that was created for it. What is happening when you look at the Task Manger in Windows (XP), it shows the memory being allocated and freed for the application, but when you look at the field called "Commit Charge" within Task Manager, it shows a constant rise in the amount of virtual memeory being used. This continues to grow until the program ends with a memory allocation error. My question relates to resources/links/recommendations on how to better handle memory within a C++ program. I am using Microsoft VC++, version 6.0. I've looked through the code for memory leaks, but it it appears to do as it should; allocating and releasing memory in the proper order. Since it appears that memory leaks is the cause, I am looking for links or recommendations on how to find these leaks. Any recommendations or resources would be greatly appreciated. Thanks in advance. Martin

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

      My first question would be why are you not using the new and delete operators?


      "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
      • M mdykstra

        Hi, I have implemented a game that adds nodes to a list; in essense it is creating a tree. When I add a node to the tree, I use malloc to create memory for the node and push it onto a stack. I then pop it from the stack and do a check. If the check passes I push it back onto the stack, if it fails, I want to delete the node so I use free() to free the memory that was created for it. What is happening when you look at the Task Manger in Windows (XP), it shows the memory being allocated and freed for the application, but when you look at the field called "Commit Charge" within Task Manager, it shows a constant rise in the amount of virtual memeory being used. This continues to grow until the program ends with a memory allocation error. My question relates to resources/links/recommendations on how to better handle memory within a C++ program. I am using Microsoft VC++, version 6.0. I've looked through the code for memory leaks, but it it appears to do as it should; allocating and releasing memory in the proper order. Since it appears that memory leaks is the cause, I am looking for links or recommendations on how to find these leaks. Any recommendations or resources would be greatly appreciated. Thanks in advance. Martin

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        Well the first thing you should do is get a memory validator program that checks for resource leaks. There are several out there, I use Bounds Checker but I sure one of the others would work just as well. It has been a while since I visited any of thier sites, but they usualy offer a 30 day free trial that you can download, so it is well worth trying. If the nodes of the tree are actualy class that allocate memory, you could be leaking it there. Since malloc and free no nothing about destructors and therefor will not call them, use new and delete instead. You could also try using the memory validation functions in the SDK, they require adding additional code to your program inorder to use them, but I understand they work quite well. I beleive there is at least one article at CP some where, on this subject. Good Luck! INTP

        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