Connecting Tech Pros Worldwide Forums | Help | Site Map

Huge problem with memory usage

Christian Br?nnum-Hansen
Guest
 
Posts: n/a
#1: Jul 22 '05
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

Phlip
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Huge problem with memory usage


Christian Br?nnum-Hansen wrote:
[color=blue]
> 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.[/color]

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.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces


Pete Becker
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Huge problem with memory usage


Phlip wrote:[color=blue]
>
> 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.
>[/color]

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>

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Christoph Bartoschek
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Huge problem with memory usage


Christian Br?nnum-Hansen wrote:
[color=blue]
> 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.[/color]

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

Christoph
Christian Br?nnum-Hansen
Guest
 
Posts: n/a
#5: Jul 22 '05

re: Huge problem with memory usage


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.
Peter van Merkerk
Guest
 
Posts: n/a
#6: Jul 22 '05

re: Huge problem with memory usage


"Christian Br?nnum-Hansen" <bronnum-hansen@mail.dk> wrote in message
news:a7b3881b.0402030635.b06b5b6@posting.google.co m...[color=blue]
> 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.[/color]

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.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


Closed Thread