Memory Leak Found by Leaks Instrument (iOS) - 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

Related

High Memory usages and after that app crash ,when using Multiple image selection library in Swift

I am working on multiple image selection, here i used a library BRImagePicker inside project. the issue is that when i start using this libraries functionality it uses memory in high volume and after that app crash with this error message "Message from debugger: Terminated due to memory issue".also checkout the image of memory uses and help me to resolve this issue.
If you look at the BRPhotoPickerController.m file under Controller group, there is a line:
info.originalImage = [UIImage imageWithCGImage:[representation fullResolutionImage]];
A memory is allocated for each photo/video in the library.
This image or video is in its full resolution which means memory will get full within seconds after the picker is presented.
The approach is inappropriate since the original photos/videos are retained in memory.
Instead what you can do is to keep a reference like the media's URL and refer back to it later.
This thread may also be helpful.
Since you have not shared any code, I encourage you to read these articles to find the memory leak and/or zombie objects:
Find memory leaks in iOS apps with XCode Instruments
Identifying Memory Leaks using the Xcode Memory Graph Debugger
Xcode Instruments — Zombies
Update:
The original library is outdated, its last update was 4 years ago and I assume you are porting it to Swift. What Soroush pointed is the what I said earlier. You should not keep a lot of UIImages in memory, to fix it you need to both keep reference to assets, and unload invisible cells. To get an idea check this library https://github.com/tilltue/TLPhotoPicker .

how to solve iPhone app memory leak in xcode(instruments)

Now i'm developing iPhone app but it seems happen memory leak. I found by Instruments:
I have question:
-- how to find where is code that happen memory leak about "Malloc xx bytes"?
-- I think I can't improve memory leak in Library. Example for "Foundation", "StoreKit" and so on, right?
Switch to the call tree view to find the areas of your code allocating the leaked memory. For more detailed information, see my answer to the following question:
Unable to track memory issue
Also for clearer representation of memory leaks select Allocation tool, go to File>Recording Options and tick "Discard events for freed memory".
In this way all the spikes that you will see in the chart will be actual unfreed memory

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

Amount of memory used by each thread

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.

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