You are registering a new mouseout event listener every time you
showPopup
. This itself is a memory leak and the root of your problem.
Something like this will work much better:
var map, wmsLayer, point, popup;
function hidePopup(event){
popup.destroy();
}
function showPopup(event) {
popup = new OpenLayers.Popup('photo', point, null, 'popup', true);
map.addPopup(popup);
}
window.onload = function(){
...
markers.addMarker(marker);
marker.events.register("mouseover", marker, showPopup);
marker.events.register("mouseout", marker, hidePopup);
...
}
Update per comment:
Storing it in an array is not really a problem, but not ideal in my opinion. If you wanted to save a popup for every single marker, I would attach it to the marker like so marker.myPopup = new new OpenLayers.Popup('photo', point, null, 'popup', true);
. No need to consolidate/sync array and markers.
However, There would be no reason for this if are destroying them on mouseout
. You would benefit from storing the popups from the 100 markers in ONE single popup
var (NOT AN ARRAY). Because you don't plan on having more than one open at any given time. So only ONE will exist at any given time because you are calling destroy()
on mouse out. So create the popup and generate its contents on mouseover
and destroy it on mouseout
.
popup
var doesn't need to be global, but it has to be in scope.
The way it is in your jsFiddle, if you console.log(marker.events.listeners);
within showPopup(point, marker)
you will clearly see that the mouseout
has as many listeners as you mouse in and out of your marker. For example, I hovered over your marker 9 times and it is creating a new listener every time:

Don't register the mouse out event listener on showPopup
unless you plan on clearing the previous listener. Or you will get the above error/memory leak.