简体   繁体   中英

Memory issue in mono touch application

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..

Thanks

When working with UIImage and UIImageView you should wrap your code into using statements or dispose the images manually if you don't need them anymore. The reason is that the managed version of UIImage basically only consists of 4 bytes, a pointer to a memory region that holds the image data. The image itself is unmanaged. This means that there is no pressure on the GC because it only sees the managed world. If you cannot do that because you need to hold all the image data in memory, you'll need to rethink your design. iOS devices only have a very limited amount of RAM and just because you can apply the full power of .NET to the device, doesn't mean that you also should do that. Try to be a good memory citizen.

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

// Here, the image data will be freed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM