PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Memory problem with destroying surfaces

golan_trevize_x · 27 Jan 2006, 12:11 UTC
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
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?
golan_trevize_x · 27 Jan 2006, 22:47 UTC
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.
golan_trevize_x · 27 Jan 2006, 23:19 UTC
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.
golan_trevize_x · 29 Jan 2006, 02:20 UTC
I found the leaks!!

It turned out there WAS a place where the heap was being used that I hadn't accounted for - my levels are loaded from XML, and I used the MSXML library through COM, and I wasn't releasing the COM objects properly.

Thanks for your help anyway guys,

Nathan