The Heap!

Hey all,

I had a couple of questions regarding the Internal Profiler, and the allocated heap section. Basically when I run this Internal Profile on my app the allocated heap always grows when loading a new scene.

For example during my intro scene the allocated memory is ~19MB when I load into my game play scene the allocated memory raises to ~35MB. Now when I reload my back intro I notice the allocated memory heap doesn’t reduce to ~19MB it actually holds at ~35MB, and will continue to climb strangely as I load scenes. the used heap memory lowers down to roughly what it should be for that scene but the used heap memory also slowly climbs causing my allocated heap to climb.

My main question about all this is if I change scenes and the previous scene allocated more RAM in the heap, should the heap lower if I load into a scene that has less RAM usage, or is it normal for it to stay at the last max allocation?

It should stay at the previous size. What the garbage collector does at the start of the app is that it just allows you to allocate memory and keeps increasing the size of the heap. When it has an idea of how large the heap should be on average it will begin invoking the garbage collector. This is why one of the tricks for having the garbage collector invoke less is to allocate large buffers at the start of your game and then release that memory. This will bloat the heap and increase the heap size at which the garbage collector is invoked.