0

We have a mono touch application that contains lots of UIImage and UIView objects. When we install the application (IPA) file in iPad (Version1) then start working, if we continue working for 10 to 20 minutes continuously then it crashed due to low memory.

We also tried Intruments profile to track heap allocations but it showing memory keep on increasing for each screen navigation. We disposed all the allocated objects in viewDidDisappear and even though memory not getting decreased. We also try to manually force garbage collector to collect the garbage through GC.Collect(), but it also not working.

Is this a bug in mono touch? or we missed memory management techniques?

Please help me to fix the Low memory warning issue..

谢谢

4

1 回答 1

3

使用时UIImageUIImageView您应该将代码包装到using语句中,或者如果不再需要图像,则手动处理它们。原因是 UIImage 的托管版本基本上只包含 4 个字节,一个指向保存图像数据的内存区域的指针。图像本身不受管理。这意味着 GC 没有压力,因为它只看到托管世界。如果您因为需要将所有图像数据保存在内存中而无法做到这一点,则需要重新考虑您的设计。iOS 设备只有非常有限的 RAM,并且仅仅因为您可以将 .NET 的全部功能应用到设备上,并不意味着您也应该这样做。努力成为一个好的记忆公民。

using(UIImage image = UIImage.FromFile(...))
{
  // Process the image.
}

// Here, the image data will be freed.
于 2013-07-31T11:23:28.467 回答