.setMap(null) will remove the marker and release any resources the marker
was holding.  You can subsequently call .setMap(someMap) to reuse it.

.setVisible() is for fast showing and hiding.  It is not intended to release
any resources.

On 22 Sep 2010 04:40, "DRI" <[email protected]> wrote:
>
> Is marker.setVisible() the best way to show/hide a marker? please note
> that the marker is needed and may be displayed in the future so
> removing it from the map may not be a good idea.
>
> Also there seems to be a memory leak in IE8. The following code
> creates 200 markers and randomly hides 20 of them every 1.5 secs. With
> IE8 the memory usage goes up rapidly with time
>
> <!DOCTYPE html>
> <html>
> <head>
> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
> <style type="text/css">
> html { height: 100% }
> body { height: 100%; margin: 0px; padding: 0px }
> #map_canvas { height: 100% }
> </style>
> <title>Google Maps JavaScript API v3 Example: Map Simple</title>
> <script type="text/javascript" src="http://maps.google.com/maps/api/js?
> sensor=false"></script>
> <script type="text/javascript">
>
> var map=null;
> function initialize() {
> var myLatlng = new google.maps.LatLng(35.772096, -78.638615);//
> 41.875696,-87.624207);
> var myOptions = {
> zoom: 12,
> center: myLatlng,
> mapTypeId: google.maps.MapTypeId.ROADMAP
> }
> map = new google.maps.Map(document.getElementById("map_canvas"),
> myOptions);
>
> setTimeout(createMarkers, 1000);
> }
>
> var markers = [];
>
> function createMarkers() {
>
> var lat = 35.772096, lon = -78.638615;
>
> // create 10x10 markers
> for (var i=0; i<10; i++) {
> for (var j=0; j<10; j++) {
> markers.push(new google.maps.Marker({map:map, position: new
> google.maps.LatLng(lat, lon),
> flat:true, zIndex:(i+j)}));
>
> lon -= 0.01;
>
> }
> lat += 0.01;
> lon = -78.638615
> }
>
> var lat = 35.76, lon = -78.638615;
>
> // create another 10x10 markers
> for (var i=0; i<10; i++) {
> for (var j=0; j<10; j++) {
> markers.push(new google.maps.Marker({map:map, position: new
> google.maps.LatLng(lat, lon),
> flat:true, zIndex:(i+j)})); //icon:'shelter_icon.png',
>
> lon -= 0.01;
>
> }
> lat -= 0.01;
> lon = -78.638615
> }
>
> setInterval(toggleMarkers, 1500);
> }
>
> function toggleMarkers() {
> // randomly hide 20 markers
>
> for (var i=0; i<markers.length; i++) {
> markers[i].setVisible(true);
> }
>
> for (i=0; i<20; i++) {
>
> markers[Math.floor(Math.random()*markers.length)].setVisible(false);
> }
> }
>
> </script>
> </head>
> <body onload="initialize()">
> <div id="map_canvas"></div>
> </body>
> </html>
>
>
> --
> You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
> To post to this group, send email to
[email protected].
> To unsubscribe from this group, send email to
[email protected]<google-maps-js-api-v3%[email protected]>
.
> For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.

Reply via email to