Using NSTimer is Swift causes 'deinit' not to call -


after using nstimer, class deinit method never called. class written in swift, , call timer @ "init" so:

init(eventsdistributor : eventsdistributor, orderside : order_side, stockviewmodel : stockviewmodel, ordertype : order_type_enum, orderprice : nsnumber) {     self.eventsdistributor = eventsdistributor     self.orderside = orderside     self.stockviewmodel = stockviewmodel     self.ordertype = ordertype     self.orderprice = orderprice     super.init()     _events()     loadpreorderdetails()      //here call timer:     var reloadtimer = nstimer.scheduledtimerwithtimeinterval(10.0, target: self, selector: "loadsecuritytradeinfo", userinfo: nil, repeats: true)     reloadtimer.fire()         } 

i tried using nstimer local variable too, , no success there... facing issue? there timer can use in swift not causes class not dealloced? thanks

the timer has strong reference target (self). , target scheduled run loop, holds strong reference until timer invalidated. until invalidate timer (reloadtimer.invalidate, or within loadsecuritytradeinfo method), object won't go away.

which good, because timer sending loadsecuritytradeinfo message object very, bad idea after object has gone.

loadsecuritytradeinfo should changed method takes timer argument, can invalidate it.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -