Thread: Memory leak, virtual memory, and other matters of grave concern

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    32

    Memory leak, virtual memory, and other matters of grave concern

    Hi,
    I'm writing a simple 2d strategy game in space.
    As in any startegy game I have databases for:
    Entities (units), each containing a pointer to an engine (everything about it's movement) and a gun (every thing about it's combat capabilities)
    Resource asteroids
    Trail marks (that ships leave when flying around space, simmilar to homeworld)
    Bullets (what ships fire at each other at high speed)
    Motherships (one per player)
    and explosions (that occur when something gets destroyed)

    All of these are implemented using full OOP, each is an instance of a class and they are all goathered in different dynamic lists...

    everything works well, I remember to deallocate everything as soon as it is no longer needed...

    I use SDL

    My question: why, after leaving the game running and about 50-60 harvesting units collecting resources around the map, do i get a message from windows saying virtual memory had been enlarged to fit my program's needs?
    Maybe each instance of each class is too large in memory? maybe I should limit my game to less units? how do other games like warcraft can include much better grpahics and bigger databases without using the hard drive based virtual memory?
    how can i make sure for suuuuuure that there is no memory leak involved?! HELP

    btw:
    all bullets,explosions, trail marks and so on that get to a certain age, expire - meaning - i delete them successfully from the databases... what's going on?!

    Thanx
    Warlax

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I don't think we can say for sure with the information you've given.

    How have you verified that you don't have any memory leaks?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    My guess would be there is some graphics resource which is being consumed.

    If you've made a fairly decent job of the 'OO' side of things, you should be able to replace all the screen update stuff with a 'null' device. Then you just let the program run quietly over many iterations and you can see if you get the same memory leak behaviour.

    What you get will tell you a lot about where to look next.

    This kind of soak testing should be done all through development. It's a lot easier to find and fix anomalous behaviour if you detect it soon after introducing it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed