Level Loading Crash - alternatives?

So I’ve read I think all of the various threads regarding level loading crashing, yet I’m still experiencing somewhat randomly reproducible crashing on the iphone when loading a level (or the app itself).

My memory usage hovers between 25mb and 28mb. There is very little waste in that, and I’m not getting any memory warnings.

It runs fine in the editor, these aren’t null refs, rather the app being shut down by the iPhone, according to the logs.
(As an aside, I’ve lost player prefs data after it was successfully saved, retrieved, and then a crash happened - unrelated, but disturbing nonetheless)

I’m considering loading an empty level, and then using resource.Load to pull in assets 1 at a time, specifically textures, although that represents a very substantial refactoring of code. I’m wondering if anyone has tried this, or if the expected result would be better than other level switching behavior.

I know Pirate Ninja alliance mentioned creating all of zombieville in one level. Is that still the best solution? I haven’t tried simply loading empty levels after discarding a full one, but if the process of simply clearing a full level is too much for the iPhone, then these levels simply won’t do at all.

Also, there is Application.PreloadLevel . Has anyone had better luck using that? I’ll still need to do something to address the startup crash (even though it only loads a single 1024 2MB texture…)

The iPhone, iTouch will automatically shut down an application the moment it exceeds the allocated memory space. It sounds like you are creating objects on the fly and at some point creating too many.

I have seen this happen when people have too tight a margin on their object memory. In a certain shooter for instance, I was able to crash it simply by missing a few too many ships on a certain level. The game continued to spawn other waves just a fraction of a second before the missed ships would have left the screen. Presumably this meant it had to grab more memory and simply overstepped it’s bounds.

preload level would make any memory bound situation actually massively worse as you not only have the current levels data in memory but also another levels data. thats near granting a crash

@dreamora I’d certainly agree if I thought this were entirely a memory issue, however the errors are not indicative of that, rather that the level took too long to load, and the iPhone presumed a process was stuck. I’m guessing this I can avoid with preloading.

If it were in fact memory related, crashes should happen ANY time there is a memory spike in the logs. These spikes more often correspond to mid-level events such as objects coming into view for the first time. In my case, the crashes are 100% related to the pause between loading levels. Of course, that doesn’t rule out that the loading process itself is using a lot of memory, but that isn’t reflected by the instruments. Rather, loading uses 100% CPU.

@Peter D I’m definitely not spawning objects on the fly. And by objects, I mean heap allocated objects, not just game objects. In fact, I’m not using coroutines either, because they bleed memory (causing more frequent GC, not actual leaks)- I’m not using the built in GUI for the same reason. My memory usage is pretty tight.