0

I am currently creating a game that requires a user to switch view controllers - when switching between levels.

Accessing a level from the menu page I use present modally. when returning back to the menu page I use the following code:

@IBOutlet weak var Menu: UIButton!
@IBAction func returntoMenu(_ sender: UIButton) {
    self.dismiss(animated: true, completion: nil)
}

This means that when the user presses the menu button they return to the menu page. However I noticed that every time the menu button is pressed the memory usage goes up rather than down. This suggests that the level isn't being closed properly.

does anyone know what might be causing this problem,

thank you in advance!

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Bushers
  • 5
  • 4

1 Answers1

0

By default iOS uses Automatic Reference Count. It means that each object has at least one strong reference with previously created (strong reference) object. If reference is removed the Garbage Collector clears this part of the memory. Of course, I mean heap. If two items have their own strong references with each other this state means 'retain cycle'. So, memory will never release. You have to post more code to find the problem. I just described a simple case. There are a lot of states when the application consumes a lot of heap memory.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194