0

Hello my question is maybe General I am not asking for code etc. I developing only for iPhones with iOS6.1 and above

When I run my application the RAM it uses only grows up(when I switching between views (I have like 15 views)).

However after I ran test with analyzer it didn't find any leaks. also no leaks were found in instrument leaks.

Despite my application doesn't exceed 20 mb of RAM I am still worried that something may be just not ok there.

I am using ARC ,but the ram still goes up.

Is there any way I can check what can cause 1 sided ram allocation ?

Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
  • 2
    How are your views connected? A view controller won't load its view until the first time it is needed, but subsequently the view will keep its allocated memory forever unless a low memory warning occurs. It's therefore natural for memory footprint to go up. Think of it like caching — not using the memory while no-one else needs it would just be an inefficient use of resources. So are you sure memory is full of objects you had expected to be deleted? Instruments will tell you what objects are using memory, or you can put an NSLog in `-(void)dealloc` if you want to see things as they happen. – Tommy Dec 22 '13 at 01:46
  • don't worry about it until your app actually crashed due to memory leak – Bryan Chen Dec 22 '13 at 01:49
  • @Tommy No I am not sure (That's why I am asking). I am using `SWRevealViewController` as Menu and all the views are inside it , I have couple more views above some inside there , but I presenting them as modalViews. So after your comment I am actually calmed :) it is my first iOS application (I am a newb) so I would be sure everything is OK :) – Coldsteel48 Dec 22 '13 at 01:49
  • @BryanChen Thanks , actually I was receiving the memory warnings when I was taking photoShoots (still never crashed) resolved it by resizing the picture in background , besides it never warnings never crash. – Coldsteel48 Dec 22 '13 at 01:50
  • You said you used analyzer to find leaks, did you mean Instruments? – Phillip Kinkade Dec 22 '13 at 01:52
  • @PhillipKinkade inside XCode Product->Analyze. – Coldsteel48 Dec 22 '13 at 01:52
  • @Tommy I think you should make an answer. – Coldsteel48 Dec 22 '13 at 01:53
  • 1
    Analyze is good, but it won't find all leaks. Profile your app in Instruments, and choose Leak Detection. It's found leaks for me that the analyzer missed. – Phillip Kinkade Dec 22 '13 at 01:54
  • @PhillipKinkade can you guide me how to do it ? (I am also not familiar with macs). – Coldsteel48 Dec 22 '13 at 01:55
  • 1
    Here's the Apple Doc: https://developer.apple.com/library/mac/documentation/developertools/conceptual/instrumentsuserguide/MemoryManagementforYouriOSApp/MemoryManagementforYouriOSApp.html Also, there are lots of good articles on the web with walkthroughs. – Phillip Kinkade Dec 22 '13 at 01:58
  • @PhillipKinkade Thank you very much Appreciate this :) – Coldsteel48 Dec 22 '13 at 01:59
  • @Tommy When considering this sort of "cache" behavior, a good way to identify that is to repeat the offending bit of the app a number of times. If it's a simple cache-related issue, you'll see some unreleased allocations between the first and second run, but after that (after the third and fourth iteration), it should stabilize. If it doesn't (i.e. memory continues to slip away), then strong reference cycle or some other undetected leak is a likely suspect. – Rob Dec 22 '13 at 05:02
  • @PhillipKinkade FYI, there are some leaks that even "Leaks" tool won't find (e.g. many strong reference cycles). But you're quite right that running it through the Instruments will find the problem, either looking at "Leaks" tool or the "Allocations" tool. – Rob Dec 22 '13 at 05:05
  • What specifically makes you think ARC isn't working or that "something is not OK"? – Caleb Dec 22 '13 at 06:16
  • @Caleb It wasn't anything specific , please reread the question I asked about ARC and the issue that I see in my memory tracker in XCode that my ram always grows however analyzer and leak detection tool didnt find anything , so I asked how can I check it and be 100% sure. – Coldsteel48 Dec 22 '13 at 06:55
  • http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/ – Wain Dec 22 '13 at 08:56
  • @Wain I am using ARC and above question not , how is it duplicate ? I asked about ARC and asked for tools that may help to resolve the issue. After a description of his problem the actual question was "How can I periodically drain the pool (even if it's not mine). " – Coldsteel48 Dec 22 '13 at 09:29
  • What you're talking about is overall memory management and investigation. It's a general topic covered by a number of other questions. – Wain Dec 22 '13 at 13:48
  • yeah i see this question is an eyesore for ppl... sorry if so – Coldsteel48 Dec 22 '13 at 17:43

1 Answers1

6

If the memory continues to go up, it could be a variety of different things, but "strong reference cycle" is the prime suspect. Sadly, this won't necessarily show up in Leaks tool in Instruments, either.

Do snapshots/generations in the Allocations tool and identify what's not getting released (notably if it consists of any of your classes) and go from there. Specifically, run the app through its paces, then mark snapshot/generation, do a bit more, and then mark another snapshot/generation. Look at that second snapshot and see what's been allocated (but not released) captured since the prior snapshot, with a focus on your classes. You'll find the culprit pretty quickly that way.

See WWDC video iOS App Performance: Memory for practical demonstration.


For example, here is a healthy app that I profiled through the Instruments' "Leaks" tool, but I'm going to focus on the "Allocations" tool:

good

In this profile, I waited for the app to quiet down, tapped on "Mark Generation" button (resulting with "Generation A", the first flag in my timeline). I then went to a view and then dismissed it, and did "Mark Generation" again, getting "Generation B". The "Growth" column is telling me that between Generation A and B, 100kb was consumed, but not released. But I'm not worried about this yet because there might be some iOS internal cache of UIKit elements. So, I repeat this process one more time to get "Generation C". Now that's interesting, now reporting a growth of only 8.26kb, which is negligible. This, combined with a clean bill of health from the Leaks instrument makes me feel pretty good about the risk of any serious memory problems.

Now, let's contrast that with some code that has a seriously problematic "strong reference cycle":

strong reference cycle

Now this is a completely different picture, even though the process was the same "present and dismiss" process, repeated twice. This is now telling me that I had a 14mb growth between generations, and more notably, I can clearly see the problematic growth curve. What's remarkable is that while the Allocations tool is clearly catching a serious problem, the Leaks tool reports nothing.

Now, in practice, the real-world experience with the Allocations tool will probably rest somewhere between these two extremes. Your app may have its own caches or model objects that slowly take up memory, but if you're properly responding to memory warnings, you should be recovering that memory. Frankly, though, most well designed apps should not be generating memory warnings at all (usually accomplished by properly configuring caches, avoiding imageNamed where appropriate, moving to persistent storage for large or infrequently accessed data, etc.). The goal is to get to a point where the app stabilizes around some reasonable baseline memory allocation level, consistently returning back to that baseline.

But it's going to be impossible for us to advise you until you do some basic profiling of your app and diagnose the sorts of memory issues that you're having.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Thank you Ron great and educative. No , I never receive any memory warnings in my application even I left it for night running etc, my source of doubts was cuz in XCode memory tracking always goes up, when I am opening new view , however the analyze inside XCode and leaks inside instruments didn't find anything ,I will try the allocations as soon as possible, Thank for your answer/guide . – Coldsteel48 Dec 22 '13 at 06:49
  • Roma- did you turn Zombies off? If those are enabled, memory will not be released – Peter Johnson May 19 '15 at 12:51