1

I'm dealing with a strange problem where tapping the button once triggers constant memory growth (but doesn't with certain lines of code commented). It also prevents the button from actually working (I noticed UIViewIgnoresTouchEvents being called in the second picture). The answer could be painfully obvious but I just can't see it. I've highlighted in red the areas where things go awry.

enter image description here enter image description here

enter image description here

I'm new to instruments and can't properly make sense of everything so I've narrowed down what seems to cause the problem in my code: lines of code with .text appear to be responsible, such as:

let formatterHighscore = NSNumberFormatter()
formatterHighscore.numberStyle = .DecimalStyle
highscoreLabel.text = "" + formatterHighscore.stringFromNumber(Int(highScore))!

or even something as innocuous looking as this:

if ... {
    exampleLabel.text = "You won!"
}
else {
    exampleLabel.text = "You lost..."
}

But in this case only when exampleLabel.text = "You lost..." is uncommented. It all seems very fickle as sometimes this sort of code makes the growth occur and other times it doesn't.

Any advice would be great

Tim
  • 583
  • 1
  • 6
  • 18
  • Just a long shot, but you might want to look at `autoreleasepool()` function from `Foundation`. – 0x416e746f6e Jan 03 '16 at 14:15
  • The tool you want to use in Instruments is called Heap Shot. See http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/ The other setting you'll want to use is "Invert Call Tree" (the default is generally more confusing than helpful). This kind of problem is poorly suited to StackOverflow because it really requires all of the code, since the problem could be almost anywhere. – Rob Napier Jan 03 '16 at 16:15
  • I've discovered it's caused by labels whose no. of lines is set to anything other than 1 when their text is changed with .text statements. It seems like a bug in pre iOS8 as it's similar to this problem: http://stackoverflow.com/questions/25398312/automatic-preferred-max-layout-width-is-not-available-on-ios-versions-prior-to-8 But I have no way of testing if it's exclusive to iOS8 as I only have an iPhone 4 restricted to iOS7.1 – Tim Jan 07 '16 at 07:05

0 Answers0