I noticed that in some examples at developers.apple.com Apple is
adding event listeners on the fly and removing them as soon as they
are not required. In the drag-n-drop example they add the touchmove
and touchend events at the end of the touchstart:
this.element.addEventListener('touchmove', function(e) { return
self.onTouchMove(e) }, false);
this.element.addEventListener('touchend', function(e) { return
self.onTouchEnd(e) }, false);
and they try to remove them on touchend:
this.element.removeEventListener('touchmove',function(e){return
self.onTouchMove(e)},false);
this.element.removeEventListener('touchend',function(e){return
self.onTouchEnd(e)},false);
As far as I can tell there's no way to remove an anonymous function
with removeEventListener. Initially I thought it was a webkit feature
but it turned out that the events are indeed never removed, so at
every touchstart two new events are appended (a big memory problem).
a very quick and dummy solution could be to create the event with
something like:
this.element.addEventListener('touchmove', obj = function(e) { return
self.onTouchMove(e) }, false);
and remove it with:
this.element.removeEventListener('touchmove', obj, false);
I'm not trying to discredit the examples at developers.apple.com, they
are great source of inspiration. I know that the examples are just
there to show you the way... they are not meant to be cut-n-pasted on
real projects, but since I slipped on this issue, I thought it could
have been worth mentioning about it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"iPhoneWebDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/iphonewebdev?hl=en
-~----------~----~----~----~------~----~------~--~---