Currently my iPad app crashes in the middle of calling Instantiate. The line it fails on is this exact line (I have debug output before and after it). I can't replicate the crash on my mac in the editor.
where undoData is an array of Texture2D objects and undoData[currentIndex-1] is not null (I've checked)
I initially thought that this could be to do with memory. I ran the internally iPad profiler which gave:
As you can see there is plenty of allocated space in the heap.
Is it possible that I have run out of video memory? Is there a way to check this? How could I go about debugging this problem?
It definetly is a memory warning. I've been able to find a
message hidden further up above the profiler. This suggests that the used heap / allocated heap values don't reflect the full story and can't really be trusted :/
Problem solved - but why?
This problem was indeed caused by a memory leak. When replacing the texture on the material, I did not destroy the previous texture, which resulted in the replaced texture remaining in memory.
before the replacement of the texture:
Note that a memory warning was not always produced by the internal profiler.
I still don't understand why this occurs? Shouldn't the memory be collected by the garbage collecter once there are no references pointing to the old texture? Forcing GC.Collect() doesn't work either.
Unity could internally keep a reference to the texture, so there is no guarantee.
I don't know iPads architecture but it is possible textures were maintained in special texture memory (video memory) that was running out, which might not be part of the heap/stack memory.
answered Mar 13 '11 at 01:30 AM