Select to view content in your preferred language

Disconnecting Events and Handlers

846
4
Jump to solution
10-22-2012 04:58 AM
SunilPalkar
Deactivated User
Hello All,

Good Morning,

I am new one to JSAPI . Its regarding to events and handlers.

I read some wherever that you need to disconnects events to avoid memory leaks. Is it necessary because in my sample application I am using lots of events on mouse move ,mouse click  etc.

So any help with proper explanation will be great !!
0 Kudos
1 Solution

Accepted Solutions
__Rich_
Deactivated User
0 Kudos
4 Replies
__Rich_
Deactivated User
0 Kudos
SunilPalkar
Deactivated User
Thanks for your reply....but is it essential ??  because I have used this in my application and not able to see the big difference after using this..

dojo.disconnect
0 Kudos
StephenLead
Honored Contributor
Thanks for your reply....but is it essential ??  because I have used this in my application and not able to see the big difference after using this..


Try something like this:


//Run this code to start the listener
listener = dojo.connect(layer,"onMouseOver",function(evt){
  //do something on hover
}
//run this code to disconnect the listener
dojo.disconnect(listener)

0 Kudos
BenFousek
Deactivated User
You don't need to worry about memory leaks on page unload from event handlers. Javascript frameworks like dojo and jquery do clean up, including removal of event handlers, when the page unloads.

Of greater concern is performance of the application while it's running. Asynchronous web apps can use up a lot of memory fast. https://developers.google.com/speed/articles/optimizing-javascript Check this out for ways to improve performance and avoid coding that may cause memory leaks.
0 Kudos