Page 1 of 1

Memory problem with destroying surfaces

PostPosted: Jan 27, 2006 @ 1:11pm
by golan_trevize_x
I noticed a post similar to this, but not sure if I am having the same problem.

In the game I am making, the player can move from one level to another. When this happens:
- the many small CGapiSurfaces created for the old level are destroyed, and the heap memory freed.
- the new level is loaded, and it's surfaces are created.

I would have expected that returning to the first level again would mean no extra memory would be needed, but the game seems to be drawing more and more from the device's physical and virtual memory every time the level changes, until I simply can't move to a different level anymore.

In order to monitor the heap, I have made my own private heap pool and overloaded the new and delete operators, and all of my new and delete statements seem to be doing fine. But I can't see what Gapidraw is doing when it creates and frees the surfaces.

It seems like Gapidraw is designed for all surfaces to be loaded at the start, rather than loading and freeing throughout the game. Perhaps this is the problem for me?

Any help would be appreciated.

Nathan

PostPosted: Jan 27, 2006 @ 2:22pm
by ppcStudios
One thing that I've done in the past is create generic reuseable surfaces at the start of the application. I then recreate these surfaces as my needs change (new graphics with different sizes, etc). At exit time I would then simply destroy the surfaces.

I have done it as you describe as well - create and destroy surfaces as needed - with success. In fact, this is what is done in Ancient Evil, and we've not experienced any memory allocation/deallocation issues.

You might try creating a simple application that creates and destroys surfaces and monitor it for correct functionality. Are you testing this issue in the emulator or on an actual device?

PostPosted: Jan 27, 2006 @ 11:47pm
by golan_trevize_x
I am testing on the device (an O2 Xda II). I've never actually used the emulator.

Since I have overloaded all new and delete operators in my code, the only place where the rest of the heap memory is being sucked away is in the creation of surfaces.

I have just confirmed using a global counter that every CreateSurface call has a corresponding deletion of the surface object.

PostPosted: Jan 28, 2006 @ 12:19am
by golan_trevize_x
I've been reading a few other posts - do you think the problem could be that my heap memory is getting very fragmented? When loading a new level, there is heaps of NEWing and DELETEing, not only to create the surfaces but with temporary data inbetween as well.

PostPosted: Jan 29, 2006 @ 3:20am
by golan_trevize_x