Track iOS UIWebView memory consumption - ios

We are working on HTML5 application - it consists of single WebView and some native parts.
But there is a huge memory leak(memory warnings and then crash) and we don't know if that WebView or native part...
So is there any way to track memory consumption by UIWebView or track object allocations to find who is leaking - WebView or native parts ?

Build your application in Xcode with the Profiler tool (command - I). In this, you are able to use a number of different tools to track memory allocations, leaks, zombies, etc..
Additionally, when profiling system resource utilization, I recommend you do all of this testing on a real device to ensure accuracy.

Related

True memory usage of my application

Which memory usage reporting method should I use when my application crashes due to low memory? There are few options:
Allocations instrumentation tool
Activity Monitor instrumentation tool
VM Tracker instrumentation tool
Xcode debugging sessions memory reporting
mach_msg_type_number_t.resident_size
The problem is that every method returns different results.
Allocations instrumentation return much smaller values than other methods - I assume Allocation only counts memory explicitly allocated inside application, but not memory used by my my app code and other libraries code? Am I right? On 512MB devices Allocation reports as low as 70MB of allocated memory and application still receives memory warnings and eventually crashes. Can I somehow measure what this difference is exactly?
Xcode debugging sessions memory reporting and mach_msg_type_number_t.resident_size varies vastly. They are sometimes 50MB away from each other, both ways. Why is that?

iOS memory usage increasing, can't find the culprit

I'm attempting to download a large number of images using AFNetworking 2.5 and stream them to disk. According to the memory monitor in Xcode, this is causing unbounded memory growth (and eventually memory warnings and force quits) - but profiling the memory usage using the allocations instrument shows the memory usage to be stable.
I'd like to think Xcode is just wrong here, but then why would my app be getting killed by iOS?
Instruments shows this - the peaks are Core Data queries, then the rest is the images downloading - peaks at about 9.5MB, the rest sits at about 8.5MB
I've also tried Heapshot Analysis - which shows a tiny bit of growth but nowhere near the amount reported by Xcode
Xcode's memory monitor shows this - growing by multiple MB per iteration.
Is there any way to get Instruments to show me whatever Xcode is seeing? Or is there a better instrument to use to find out where all this memory is going?
Thanks!
According to the memory monitor in Xcode, this is causing unbounded memory growth (and eventually memory warnings and force quits) - but profiling the memory usage using the allocations instrument shows the memory usage to be stable.
Believe Instruments and the Allocations information - not the memory monitor in Xcode. The memory monitor graph is completely irrelevant. Ignore it.
This is not because the memory monitor in Xcode is useless or wrong. It is because memory management is completely different for a debug build than for a release build (Instruments uses a release build). This is especially true in Swift (you don't say whether you're using Swift).
Observe memory usage only on the device and only in a release build. Otherwise, you'll be completely misled.

How to understand CPU and memory consumption in xcode debug

In Xcode 5, there's a new debug panel that shows the CPU and memory consumption in % and MB respectively. How do we make use of this? Is there a CPU % threshold I should try to stay below? I sometimes see my apps goes to 100% or over.. does that mean I am doing too much processing in my app and should try to optimize?
Any tips?
(PS. I'm developing on iOS)
A modern iPhone or iPad has 1024Mb memory.
But how much of that is available for apps is something that Apple has never divulged.
Just use as little memory as possible, and release non essential memory when the OS notifies your app about low memory.
Similarly, use as little CPU as possible, but more importantly, do not block the UI thread.
Use the profiler to find hot spots for CPU use and try to optimize those.

iOS: how to count open apps

Can someone suggest to me a way to count (inside an iOS app) all open apps on OS, to show to the user an alert if there's not enough memory to run my app?
While theoretically this is possible, it's not a good idea. First of all, the number of open apps is an inadequate measure when in fact you care about memory consumption. Next, this doesn't take into account the fact that different devices have different amounts of memory. Last but not least, if memory is running tight iOS will first kill background applications and free some memory for you.
So, don't do it. Instead, try to be a better iOS citizen: respond to memory warnings, try to cache stuff in files and read up on memory mapping (for example with mmap) to reduce your app's memory footprint.

ipad application memory warning when using little memory

I am running an ipad application compiled for release and am seing memory warnings once in a while.
When I run the app on the device and connect Instruments, I see that the app never passes 40MB of real memory, but the warnings are still occurring.
What might be causing this? How can I better track down the reason?
40 MB of real memory is a lot, for an iPad. Even if it was not, the system will deliver the low-memory warning to you from time to time anyway, without your application being the main culprit. Tracking down precise memory usage in your application is sometimes hard, I’d suggest to spend some time with the Object Allocation instrument while working with the app. If you are not getting killed and you are sure that you do not leak the memory, you can also simply ignore the warnings.
40MB is high for the iPad considering it only has 256MB to start with. There could be other applications holding on to memory which will be killed off as more memory is needed. Just make sure you aren't leaking anything. Also use NSAutoReleasePools where applicable to reduce peak memory usage in memory intensive loops.

Resources