ios - Remove event handler from memory (ortc) , titanium -



ios - Remove event handler from memory (ortc) , titanium -

i have memory leak:

var ortc = require("co.realtime.ortc"); function ortcnot() { ortc.clusterurl = 'http://ortc-developers.realtime.co/server/2.2'; ortc.connectionmetadata = 'titanium example'; ortc.addeventlistener('onexception', function(e) { ti.api.info('exception: ' + e.info); }); ortc.addeventlistener('onconnected', function(e) { ti.api.info('connected ortc server'); ortc.subscribe('yellow24', true); }); ortc.addeventlistener('ondisconnected', function(e) { ti.api.info('disconnected ortc'); //remove event handlers //ortc = null; }); ortc.addeventlistener('onsubscribed', function(e) { ti.api.info('subscribed to: ' + e.channel); ti.api.info('sending message to: ' + e.channel); //ortc.send(e.channel, 'message iphone'); }); ortc.addeventlistener('onunsubscribed', function(e) { ti.api.info('unsubscribed from: ' + e.channel); ortc.disconnect(); }); ortc.addeventlistener('onmessage', function(e) { ti.api.info('message received: ' + e.message + ' @ channel: ' + e.channel); //parse message var message = json.parse(e.message); alert(message.user.message); //check chat id if (message.id == args.chatid) { recievemessage(message); } //ortc.unsubscribe(e.channel); ti.api.info(ortc.isconnected()); }); ortc.connect('yellow2'); } ortcnot();

when close controller window, reopen window. old event listeners still in memory, causing duplicate event listeners created.

any thought why happening,and how solve it? thanks

instead of defining listeners in-built function, declare them calling function.

to remove eventlistener has identical in both addeventlistener , removeeventlistener, declaring function , assigning eventlistener gets around this. e.g.

var viewobject = null; function eventtodo(){ // stuff here ... viewobject.removeeventlistener('click', eventtodo); } function addlistener() { viewobject = ti.ui.createview(); viewobject.addeventlistener('click', eventtodo);  homecoming viewobject; }

when close window not calling removeeventlister why every time window opened events beingness duplicated. attach close event window object in question calls function remove eventlisteners removing them applications memory.

ios titanium-mobile titanium-alloy ortc

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -