1

run a mapview in xcode waste too much memory, so that i want to remove the mapview when current ViewController dismiss:

deinit{
    mapView = nil
}

but in the debug navigator, memory didnt release in fact. so , how to release the memory when i remove the mapview? thanks!

Suraj Sonawane
  • 2,044
  • 1
  • 14
  • 24
LukasTong
  • 1,861
  • 2
  • 10
  • 7
  • Possible duplicate of [In Swift, how to remove a UIView from memory completely?](http://stackoverflow.com/questions/34555765/in-swift-how-to-remove-a-uiview-from-memory-completely) – 0x416e746f6e Jan 04 '16 at 10:33
  • Try to remove MapView holding view from its super view. Or check for any pointing references present currently or not. – Suraj Sonawane Jan 04 '16 at 11:08

2 Answers2

0

Basically, one way to release the allocated memory for your mapView outlet is to call the .removeFromSuperview() method, put this in your viewDidDisappear declaration

override func viewDidDisappear(animated: Bool) {
    mapView.removeFromSuperview()
}

The superview (in this case my ViewController) was able to free the memory accordingly

0

Swift uses Automatic Reference Counting mechanism for memory management and this means that the object will be removed and unloaded from memory at the time when the reference count, which refer to the object becomes zero. If the object is not unloaded, it is likely that the program has other objects that use it. Try to go through the code and check that you don't set reference to it object inside another objects

Alexey Pichukov
  • 3,377
  • 2
  • 19
  • 22