Virtual memory issues with MonoTouch - ios

We have a hybrid Web/Native application built using MonoTouch and a UIWebView. The application stores encrypted images on disk which are then requested by the UIWebView, decrypted on the fly (via an NSUrlProtocol) and then displayed in the application.
Everything works well until we have around 27-30 images at which point we receive memory warnings and the application then crashes.
Profiling the application using Instruments we see our real memory is ~ 55MB however our virtual memory is ~ 800 MB which seems quite high. Also our physical memory seems to spike near the end.
I realise this is probably an issue with our application however we are at a loss at how to diagnose the issue. If anyone has any thoughts it would be greatly appreciated.
A couple of things we have tried:
Monotouch profiler (only showing ~ 2mb usage)
GC.Collect() (No change)
Thanks,
James

Related

Jetsam kills WebGL application on iOS

I am currently struggling with memory management inside a webgl application on the web, on iOS only.
I keep getting the following error message :
Application 'UIKitApplication:com.apple.Preferences[0xa7c1]' was killed by jetsam.
I understand that Jetsam is the system process responsible for memory management, but the crash occurs while the browser uses around 25% of the device's RAM, which is not that high. I don't have any other open application while running my webGL content. What I don't understand is what Taun Chapman said :
Jetsam monitors memory use and kills applications which are not good memory citizens. A good memory citizen is an application which is willing to give back memory when asked and does not keep asking for more memory.
Well, the app needs more memory in a short time (when unzipping 3D models using workers), I can't continue my app without it! And it crashed at these particular times.
Moreover, I think I have some memory leaks in my app, according to Chrome DevTools I am currently trying to fix. But the browser itself seems to have some leaks too. Thus, fixing mine will just delay the inevitable.
I know the following question is odd, or inappropriate, but do you know if the jetsam "limit" can be increased ? Or if you can add an exception on the currently running WebGL app ?
For your information, I use the Three.js WebGL library and the zip.js library to compress my 3D models.
Yes, I've already read the following question : Why does simple website crash on mobile (iOS Safari and Chrome, at least)?, but the problem does not come from my CSS.
The 10.3.2 version of iOS (released the 15th of May) made Jetsam less aggressive, or at least, the memory is better handled.
https://support.apple.com/en-gb/HT207798

Unmapping memory-mapped images that are created during processing

I have a pretty big issue, although I only have the symptoms, and a theory on the cause.
I have a C++ application under Windows 7x64 that uses system calls to FFMPEG 0.7.13 to extract frames from videos. When running, the parent application maintains a nice, predicable memory footprint in memory profilers (task manager, RAMMap) of about 2MB. I can see the individual calls to FFMPEG also come and go without incident. The trouble is, after about 100 calls to FFMPEG, and 70,000+ PNGs created (no one directory has more than 1500 pngs), the Windows memory page size raises gradually from about 2.5GB to over 7.0GB, and the system is brought to its knees. The sum of the processes for all users is no where near the reported Memory Page amount.
I thought it might be Windows Search indexing related, so I turned off the indexing for the output directories in question using SetFileAttributes() and FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, and while it seems to be working as advertised, it does not seem to combat the issue at hand. My current running theory is that all of these extracted PNGs are either fully or partially memory mapped, by FFMPEG or something else. I can also see the output PNGs under the RAMMap Physical Pages tab as standby mapped files.
Question:
- Is there enough information here to possibly diagnose the exact problem?
- Do I have a way to combat this issue?
Thanks in advance...

Difference between virtual memory consumption and real memory with Memory Monitor on iOS

I am stuck with an issue in my app. I have been testing up until now mostly on my iPad 3 with occasional checks on my iPad 1 to make sure all is well.
I am playing a UIImageView animation in my app and it keeps quitting with only a "Received memory warning" message before it quits.
I have been using the Object Allocations tool in instruments but according to that, my memory usage is way low. So after researching for a bit I came across this post by Mr. Larson: https://stackoverflow.com/a/5627221/329900
Now I am using the Memory Monitor tool instead. However, I don't understand why I am quitting. The 1st gen. iPad has 256MB of ram. Now I know I can't use all of that...some say you shouldn't use more than 100MB.
Is that real memory though, or virtual memory...or maybe some combination? My real memory is consistently between 20 - 25MB but the virtual is around 190 - 205MB when it crashes.
Here's a screenshot:
Anyone able to shed some light on this?
The WWDC (Session 242) video found by searching for iOS App Performance: Memory in the WWDC 2012 Session Videos page will give you a better understanding of the difference between VM and real memory.
But here is a quick overview:
A pointer Range = 2^32 = 4GB This is larger then the physical memory on any device(apple has shipped). This is done by taking all available space and dividing it up into 4kb chunks. Not all the memory your application can access is in physical memory at the same time. These 4kb chunks are call pages. Your allocations get split out of larger chunks of virtual memory. Then these virtual memory objects get mapped to physical memory.

Apple maps memory footprint

Did anyone had or have problems with the memory footprint (Live Bytes) when using the new Apple maps in an iPad application?
I tested my iPad app with Instruments and it seems the memory allocation jumps to over 70MB when displaying the map (and even 120MB when start zooming) -- while on iOS 5.1 (using Google Maps) the memory footprint is less than 4MB.
Or does anyone have a solution to this issue (reducing the memory footprint when using Apple maps)?
Thanks.
As I commented above, this became an issue required me to bang my head against a wall for some time. The straight answer is, yes this is an issue Apple accepts to be exists but they have some good excuses for that such as newer hardware devices should be able to handle this memory consumption without much pain. However, some people have already logged issues in their system, so there is nothing we can do until they fix it and release a patch.

Safe limit of memory usage today?

I am developing a game for iOS. The memory I am using is around 80 MB according to the profile tool (no leaks). That just seems like a lot of memory to me. How much memory usage is safe, and are there any special programming issues associated with using a lot of memory?
It's all about what devices you plan to get you game. iPads are just fine with 100 MB of ram games, iPhone 3G's don't even have 100 mb. If you use a lot of memory you app will be forced to close, this could cause major problems if the user is on an old device.

Resources