Amount of memory used by each thread - ios

I am developing an app that is crashing due to an excess of memory usage. I would like to know the amount of memory that is being used by each active thread so that I can decide which allocated or drawn in screen elements release or remove from view. Is there a way to obtain it?
I have tried using mach.h library but with mach_task_self() I can only access the memory used by the whole application.
Thanks in advance

I think what you want is logMemUsage().
You can check the Answer from this Question :
Watching memory usage in iOS
I think you can get something from this Documentation also :
Understanding and Analyzing iOS Application Crash Reports
If you want to check Memory Usage While Application is Running then use Instruments. :
Using Instruments you can check how much memory your app is using. In Xcode4, use 'Profile' build, choose Leaks, then click the Library button in the toolbar and add the Memory Monitor instrument.
If you really don't want to use Instruments then you can use Custom Class UIDeviceAdditions :
Get current Memory usage
Hope it's Enough.

You can't because threads share the heap. Threads are created with a 512KB stack space, with memory pages allocated as needed. Other than that, there is no memory per thread value stored anywhere.

Related

didReceiveMemoryWarning: what type of memory?

I have a base cordova app, with some objective-c code around cordova's framework. Sometimes I've didReceiveMemoryWarning notification, but I don't understand if the problem is the javascript inside the UIWebView or other.
The documentation says:
Your app never calls this method directly. Instead, this method is called when the system determines that the amount of available memory is low.
But my question is: what type of memory?
RAM? Heap allocations? Something else?
RAM, it is for RAM, if your app consuming more memory without realising it, and no memory to remain to process any more thread then, this didreceivememorywarning get called by system.
You should profile your app with Instruments and you'll get a better picture of what's consuming memory.
The memory issue represents to RAM, generally we are creating the app using different objects, and these objects take some memory to process the required task. If we aware about them we can easily manage the memory but sometimes for beginners it is not managable to debug the memory, and didReceiveMemoryWarning occured. We can diagnose or debug this issue by instruments.

Memory Leak Found by Leaks Instrument (iOS)

I am having trouble understanding the leaks found by the Leaks instrument right after build. Is this being caused by my own code or a library?
Let me know if you need more information, and thanks!
libSystem.dylib is a system library. If you run your app on a device you shouldn't encounter this leak anymore.
The leak is related to the way the simulator works.
looks like it some system code and it's probably allocating a permanent memory chunk. It's a very small allocation and there's only two of them. I don't think its a concern--all apps "leak" some memory.
what to watch out for:
many repeated small allocations... For example: an NSString created and leaked every time you adjust a volume slider.
larger chunks that are meant to be used once and thrown away. For example, an image loaded for a window background that isn't released when the window is closed

Potential Memory Leak in iOS

So I just made an app that loads a map with some markers on it. The app has a navigation controller that segue from the main screen to the map and back. While running the app on my phone and simulator i noticed that if i went back and forth between the home screen and the map, the amount of memory that the app was using just kept growing indefinitely. Is there way to assist in the process of memory management (i know the system uses ARC)? Im using the google maps sdk btw.
Thanks!
Does it cause the app to run out of memory and crash?
Or is it using a ton of memory, receiving a memory warning, and dumping said memory?
So, unless it is causing crashes, it may be behaving correctly.
Apple has extensive and well-documented support for diagnosing these kinds of problems. See "Locating Memory Issues in Your App".
Check your codes where using NSThreads and GCD blocks. If there are some places you create plenty of threads, it is recommended to add a autoreleasepool block.
Memory may leak in these situation:
If you are writing a program that is not based on a UI framework, such as a command-line tool.
If you write a loop that creates many temporary objects.
If you spawn a secondary thread.
For reference: Using Autorelease Pool Blocks

How to determine how much memory allocated by my app in iphone

I am having some trouble around memory leaks in my app.
I just wanted to know that whether it is possible to identify how much memory allocated by my app on heap so that i can reduce my resources accordingly.
I know that system gives low memory warnings & i can clean up my data there but even if sometimes it wont happen.
If i get to know that my app is reaching maximum memory & remaining size on heap so i could be better to reduce my resources.
Thanks in advance....
Use Instruments. Command-I in XCode to profile your app in Instruments.
Yes of course, I would recommend the instrument's tool "Leaks". It lets you know how much memory allocates your app, and if there are leaks it tells you what they are, when and were it was allocated (and obviously not released).
Here is a nice guide I used some time ago.
http://www.cimgf.com/2008/04/02/cocoa-tutorial-fixing-memory-leaks-with-instruments/

iOS, check if the app crashes because of lack of memory

How can I make sure that reason of crashes is lack of memory?
Is there anything specific in crash log?
Maybe I have to use some tools or libraries?
UPDATE: my app uses lot of memory and receives memory warnings. It's very difficult to reduce memory usage. It crashes because of memory warnings time to time. But I want to make sure that it doesn't crash because of other reasons.
So how can I check the reason of app crash (it receives lots of memory warnings every time)
UPDATE2: Application has lots of 3D graphics and complex UI that takes lots of memory for textures. Customer doesn't want to make any kind of "loading..." pauses. If I unload invisible textures in background I can't get smooth animations.
So I just need to detect is there any crash reasons except memory.
At least you could implement the method
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
in your app delegate, and put a log to see if this indeed you are going through it before crashing.
Product -> Profile -> leak is a possible method to check memory leak. Allocations will show the total memory being used, and leaks will show leaks due to not releasing.
how-to-debug-memory-leaks-with-xcode-and-instruments-tutorial
that is a useful tutorial
You can use Apple's Instruments Tool to profile various things such as memory usage. This tool is bundled together with Xcode.

Resources