Arc warning application error

I use ARC, and the application crashes with a warning of the received memory . I used apple tools:

http://tinypic.com/view.php?pic=21kedxt&s=5

It seems that I have no leaks, but I can not find where it is wrong. The crash is due to memory and due arc, I can not use the release and any kind. This is my first experience using memory using an arc. From there, I can debug this, since I have been dealing with this for almost two months. I have my code in my git node, so it will be useful if you look at it. You can find it here.

I have been tackling this problem for several weeks and want to end this. Thanks.

+4
source share
3 answers

Not all leaks appear in the Leaks tool in the Tools. And, especially, if the view controller has a strong reference loop, the controller will not be released not only, but not one of its members will be released. But, looking at your distributions, your memory is never freed, so you probably have a leak somewhere. It's hard for us to diagnose because your github project is incomplete. But here are a few thoughts:

  • Strong link loops are not always displayed in the Leaks tool.

  • According to the traditional strong reference loop, your code uses a repeating NSTimer that will contain a strong link to your view controller, which will cause your view controller to never be released (as the timer maintains its own link to your view controller). To fix this, your view controller should stop the timer when the corresponding view disappears:

     - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.timer = [NSTimer scheduledTimerWithTimeInterval: 0.05f target: self selector: @selector(tick) userInfo: nil repeats: YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.timer invalidate]; self.timer = nil; } 
  • Besides strong reference cycles, such as the one above, another phenomenon that can lead to an increase in the distribution, as you shared with us, is a circular flow between view controllers. For example, if your application does push / modal segue from view controller A to view controller B, the application should then pop / fire / cancel back to view controller A. If you press / modal from B to a new instance of A, you end up as a result, abandon your old instance of A, as a result, get a distribution graph like yours.

These are just a few examples of the things that can lead to your distribution schedule. But it’s hard for us to diagnose further information with limited information.

Before doing anything else, use the Xcode static analyzer ( command + shift + B or "Analysis" in the "Product" menu) and make sure there is a clean account there. Let Xcode help you identify your programming problems in your code.

Once you fix all the problems identified by the static analyzer, you can immerse yourself in Tools. See WWDC 2012 Video, iOS Application Performance: Memory . After about 32 minutes, it shows a distribution chart similar to yours, describes three sources of such problems (leaks, left memory, or cached memory) and shows how to use the Allocations tool to determine the exact source of the problem.

You have to follow this video and you will probably learn about the functions of the Allocations tool (such as comparing heap snapshots) to determine which object has leaked, or look at the extended information and the call tree to find the source code that the leaked object was created. Once you determine exactly what the leak is, we can help you solve the problem.


By the way, it’s even simpler than the heaps described in this video, I will often just option -click-and-drag on a specific spike (especially one that is obviously never released) on the chart in "Allocations". If you do this, the final summary of the object will show you the objects (most useful if you sort by "Live Bytes") that were highlighted and not released during this run window:

object summary

This may be useful, but sometimes it’s just a cryptic CFString or CGImage distribution. Therefore, it is sometimes useful to see where these objects were allocated in your code. If you go from “Statistics” - “Object Summary” to “Call Tree”, it will show you how much memory was occupied by each of your methods (and I find this screen most useful if I also check “Invert Call Tree” and "Hide system libraries"):

call tree

If you then double-click on the symbol name here, it will actually show you code that violates:

code sample

In this process, I can see what is allocated on this surge, and now I can determine why this memory is never freed (in this case it was my intentional use of a repeating timer, T24>).

There are other tricks that are useful in more complex scenarios (I especially like to have code signaling flags that appear in the tools, so I can more accurately match the actions in my code with what happens in the Tools), but this is probably too much to enter here. We hope this tool option -cick-and-drag in the tools becomes a useful tool for determining what is highlighted and never released.

+6
source
  • There are times when ARC does not work (by design, I mean). When you use CoreFoundation or anything even below the Cocoa level, you need to manage your memory as before. In addition, you could save loops (most often with blocks). Try to analyze the project (next to Build in Xcode) or run using tools
  • ARC does not help if you just use a lot of memory. Perhaps your data set is too large, and you need to reorganize to use less memory at a given time.
0
source

As I understand it, you are github code

  • There is one file name iCarousel.m.make, make sure it is compatible with ARC, and if not, go to the fax / phase / patch assembly and set the fno-objc-arc flag to iCarousel.m.

  • Make all objects null in the viewdidunload method for all classes.

Hope this helps you.

0
source

Source: https://habr.com/ru/post/1500117/


All Articles