Hi all,
Could you tell me how can I prevent memory leak with NSTimer function?
I was coding iOS application in Swift 2.0.
Below my code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: "timer_action:", userInfo: nil, repeats: true)
}
func timer_action(timer: NSTimer) {
print("Hello")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
When NSTimer's action called, memory leak is occured.
The code alloced 2MB in only 1.5 minutes.
I confirmed memory leak in Instruments and it shows 2MB value in "All Heap Allocations" field.
Thanks