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
Post a Comment