Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been fighting with XNA ContentManager and memory allocations for some weeks because I'm trying to port my game from XNA (Windows) to ExEn / Monotouch (iphone).

The problem is that after playing a few levels, my game exits unexpectedly on a real iPhone device (not simulator).

Profiling memory usage on Windows with CLRProfile, I found some useful stuff but I also found something I dont understand. If I use 2 ContentManagers (1 for shared assets and 1 for level assets), when profiling, "Allocated Bytes" grows and grows after level through level but Memory consumption measured by Windows Task Manager stays constant (down when I unload the content manager and up again when I load content). Obviously, I contentManager.Unload() when level ends. After a few levels my game exits unexpectedly on an iPhone device.

If I use 1 content manager, "CRLProfiler Allocated Bytes" stays constant on Windows and on the iPhone; I can play the game normally and it doesnt exit unexpectedly. I use the same assets level through level.

It seems like in ios (iPhone) when loading and unloading the same assets, it allocates memory and consumes all device memory, so the ios kill it.

Can anybody explain me how this really works?
I've read quite a bit, but I still don't understand what's going on.

share|improve this question
1  
Perhaps is a bug of the API you are using. Try a small test with MonoGame and see if it still happens. –  r2d2rigo Jan 31 '12 at 20:53
    
Yes, it was a bug of the API I was using. It's already fixed now. exen.codeplex.com/SourceControl/changeset/changes/15002 –  Vackup Jun 26 '12 at 13:35
1  
@Vackup You should add this as an answer and accept it. –  Laurent Couvidou Sep 12 '12 at 14:23
add comment

1 Answer 1

The garbage collector might work in unpredictable ways. You probably want to do a GC.Collect() at the end of your level loading logic to ensure that all releasable memory is indeed released. I don't know if there are any difference between the GC behavior in the simulator or on the device, but make sure you are making it easy for your ContentManager to be collected by null'ing all references to it and the content itself.

You might want to use the Instruments profiling tool (or something else, CLR Profiler?) while running on the actual device to check the memory allocation / release patterns and see if it's indeed a memory-related issue.

As a rule of thumb, you should avoid allocating memory during gameplay (create all game objects ahead of time or have pools) so that you can avoid accidentally triggering the GC while the game is supposed to be interactive.

Finally, try reducing your problem to a minimum reproducible test case by removing all game logic, display, anything that isn't needed to make the whole thing crash, and make sure that it still crashes. This should either help you find what you did wrong or help you locate any bugs that might exist in MonoTouch / ExEn / any other frameworks you might use.

share|improve this answer
    
it was a bug of the API I was using. It's already fixed now. exen.codeplex.com/SourceControl/changeset/changes/15002 –  Vackup Jun 26 '12 at 13:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.