Huge problem with memory usage

  • Thread starter Christian Br?nnum-Hansen
  • Start date
C

Christian Br?nnum-Hansen

Hi!

I am making a game in C++ using SDL.
But I have this big problem.
It just takes more and more memory as it runs.
It can be downloaded at:
http://www.caturn.dk/newgame.html
Does anyone have the slightest idea what the problem could be?
It does'nt declare any new variables while it runs (only in the start)
but changes the ones already declared.

Please help me. It's driving me crazy.
Christian

P.S. Sorry for my bad English
 
P

Phlip

Christian said:
I am making a game in C++ using SDL.
But I have this big problem.
It just takes more and more memory as it runs.
It can be downloaded at:
http://www.caturn.dk/newgame.html
Does anyone have the slightest idea what the problem could be?
It does'nt declare any new variables while it runs (only in the start)
but changes the ones already declared.

Rewrite your project from scratch, using "test driven development". Then you
can instrument each test to detect leaks, and the test will tell you what
subset of code's doing it.

If you simply must persist with the current code, cut it in half and see
which half leaks. Keep going until you have a very small code sample that
leaks. If you still can't see the leak, post that snip here.

Alternately, look up one of the (off-topic) heapwalk() functions, put it
into a function called "detectLeak()", and call that function everywhere.
Put a breakpoint in it, and see which code first becomes leaky.

Alternately, get a leak detector such as (IIRC) "electric fence", or
similar.

But asking all of us to read all of your code is very inefficient, unless
you - who are more familiar with the code - does some preparation first.
 
P

Pete Becker

Phlip said:
Alternately, look up one of the (off-topic) heapwalk() functions, put it
into a function called "detectLeak()", and call that function everywhere.
Put a breakpoint in it, and see which code first becomes leaky.

And start out with really, really simple test cases. Performance
typically drops through the floor when you do this, and it's easy to
fool yourself into thinking the application has crashed when it has
merely become glacially slow. <g>
 
C

Christoph Bartoschek

Christian said:
Hi!

I am making a game in C++ using SDL.
But I have this big problem.
It just takes more and more memory as it runs.
It can be downloaded at:
http://www.caturn.dk/newgame.html
Does anyone have the slightest idea what the problem could be?
It does'nt declare any new variables while it runs (only in the start)
but changes the ones already declared.

Even if one would like to help you, it is impossible without the source
code.

Christoph
 
C

Christian Br?nnum-Hansen

I will probably do the thing about cutting the code in half as it
should not be any problem the way I've written it.

But maybe there is a function which tells how much RAM is being used?
Then I could put it everywhere in the code and see where the amount of
used RAM increases.
 
P

Peter van Merkerk

Christian Br?nnum-Hansen said:
I will probably do the thing about cutting the code in half as it
should not be any problem the way I've written it.

But maybe there is a function which tells how much RAM is being used?
Then I could put it everywhere in the code and see where the amount of
used RAM increases.

There is no standard function for this, but maybe that platform you are
using has one. Alternatively you might consider using a leak detection tool
to figure out what part of your code is leaking resources.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,888
Members
47,420
Latest member
ZitaVos505

Latest Threads

Top