Hi All, I have a program which show the coordinates of vehicle at an interval of 1seconds. The vehicle is display as a marker in the map. When clicked, a pop up occurred, it will show the properties of the vehicle. When the next interval tick, the existing marker on the map will be remove and re-add to the map with different position. The pop- up will be remained open for the next interval until the pop up is manually closed.
The problem i'm having now is when the marker is clicked and pop-up, the memory usage keep increasing for every seconds. When i measure the memory usage and memory leak with sIEve, there's no memory leak, but the memory usage keep increasing as well as the inUse (DOM object created). Anyone know how to release the DOM of the openInfoWindowHtml ? i try to use the marker.closeInfoWindow() and use the GEvent.removeListener to deregister the marker click event listener, and assign related object to null but it seems not working. Here is my code. <html> <head> <script src="http://maps.google.com/maps? file=api&v=2&sensor=true&key=xxx" type="text/javascript"></script> <script src="Map.js" type="text/javascript"></script> <script type="text/javascript"> var lat = 3.1000; var lon = 100.1001; function Init() { InitMap(); alert(G_API_VERSION); PrepareAddMarker(); window.setInterval("PrepareAddMarker()", 1000); } function PrepareAddMarker() { RemoveCurrentMarkers(); RemoveEventListener(); AddStandardMarker(0, '1', 'ABC', 'vehicle 1', '10/01/10', '10:00:00', lon.toString(), lat.toString(), '10km/hr', '1', 'on'); lat = lat + 0.011; lon = lon + 0.011; } </script> <style type="text/css"> html, body { margin: 0; padding: 0; height: 100%; } #map { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } </style> <title>Live Map</title> </head> <body onload="Init()"> <div id="map" style="width: 100%; height: 100%;" /> </body> </html> //Map.js file //Common global variable ---------------------------------------- var map; var bounds; var MapIconMaker = {}; var maximumMarkerAllow = 2; var liveMapCounter = -1; var selectedRegNum = ""; var calloutWindowStatus = -1; var currentMarkers = new Array(); var marker = new Array(); var eventListener = new Array(); //Marker Objects -------------------------------------------------------------------------------- function StandardMarkerObject(markerLabel, gpsId, regNo, date, time, lng, lat, speed, isPowerOn, status) { this.markerLabel = markerLabel; this.gpsId = gpsId; this.regNo = regNo; this.date = date; this.time = time; this.longitude = lng; this.latitude = lat; this.speed = speed; this.isPowerOn = isPowerOn; this.status = status; } //------------------------------------------------------------------------------------------------ //Custom AddMarker methods ---------------------------------------------------------------------- function AddStandardMarker(count, markerLabel, gpsId, regNo, date, time, lng, lat, speed, alertType, isPowerOn) { var markerColor = "458B00"; var status = "Within speed limit"; marker[count] = new StandardMarkerObject(markerLabel, gpsId, regNo, date, time, lng, lat, speed, isPowerOn, status); var point = new GLatLng(lat, lng); currentMarkers.push(new GMarker(point)); var html = "<p style='text-align: left; padding: 5px'>" + "<b>" + "Vehicle No: " + "</b>" + regNo + "<br/>" + "<b>" + "Date: " + "</b>" + date + "<br/>" + "<b>" + "Time: " + "</b>" + time + "<br/>" + "<b>" + "Longitude: " + "</b>" + lng + "<br/>" + "<b>" + "Latitude: " + "</b>" + lat + "<br/>" + "<b>" + "Speed: " + "</b>" + speed + "<br/>" + "<b>" + "Vehicle Engine: " + "</b>" + isPowerOn + "<br/>" + "<b>" + "Status: " + "</b>" + status + "<br/>" + "</p>" eventListener[count] = GEvent.addListener(currentMarkers[currentMarkers.length - 1], 'click', function() { //mapMarker.openInfoWindowHtml(html); currentMarkers[currentMarkers.length - 1].openInfoWindowHtml(html); calloutWindowStatus = count; } ); map.addOverlay(currentMarkers[currentMarkers.length - 1]); //currentMarkers.push(mapMarker); if (calloutWindowStatus == count) { //mapMarker.openInfoWindowHtml(html); currentMarkers[currentMarkers.length - 1].openInfoWindowHtml(html); } bounds.extend(point); } function InitMap() // initialize the map { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(4.1711, 102.4804), 7); map.setUIToDefault(); bounds = new GLatLngBounds(); } else alert("Sorry, your internet browser is not supported by Google Maps."); } function RemoveCurrentMarkers() { //to maintain the status of callout window on LiveMaps if (map.getInfoWindow().isHidden()) calloutWindowStatus = -1; //marker = []; bounds = new GLatLngBounds(); RemoveEventListener(); marker = null; marker = []; if (currentMarkers.length) { while (currentMarkers.length) { var currentMarker = currentMarkers.pop(); currentMarker.closeInfoWindow(); map.removeOverlay(currentMarker); currentMarker = null; } } currentMarkers = null; currentMarkers = []; } function ClearMap(){ map.clearOverlays(); } function RemoveEventListener(){ while (eventListener.length){ GEvent.removeListener(eventListener.pop()); } eventListener = null; eventListener = []; } -- You received this message because you are subscribed to the Google Groups "Google Maps API" 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/google-maps-api?hl=en.
