Select to view content in your preferred language

Can Adding/Removing Dynamic Map Layers on the fly cause memory problems on server?

2642
2
05-01-2012 02:34 PM
BrendanLee
Emerging Contributor
I have an application that adds/removes dynamic map layers based on the user selection from a combobox.

I am using Flex API 1.9. The map services are running on ArcServer 9.3 on a Windows 2003 server.
One of the map services has 37 layers (including a couple of group layers). Should I break it up?
I'm also using labeling on a lot of the layers.

Lately we've been having issues with our server having memory problems. I suspect it is either one of my map services, or the way
my application adds/removes dynamic layers that is causing the trouble.

Here is my code for adding/removing layers. I am adding them over my base map and aerial caches.
This code is called when the user selects a new "view" from the drop-down.

Is there potential memory problems here? Something with the soc/som?

The list in the switch block is actually much longer. I just put in a few to save space

private function addLayers():void
    {   
     myGraphicsLayer.clear();
     
     // Some layers will not have anything visible at full extent
     // Add busy cursor so user knows something is happening
     // Then remove it when layer has been loaded    
     CursorManager.setBusyCursor();
     
     // Remove layers that have already been loaded
     for (var n:Number = MainMap.layers.length -1; n >= 0; n--) //loop thru all map layers
  {
   var layer:Layer = MainMap.getLayer(MainMap.layerIds);
   if (layer.id == "viewLayer" || layer.id == "viewLayer2")
   {
    MainMap.removeLayer(layer);
   }
  }

   // Create 2 new Dynamic Map layers 
     var lyr:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer;
     var lyr2:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer;
     
     // Create an array collection so only certain layers can be displayed
     // If nothing is added to this ArrayCollection all visible layers in mxd are displayed
     var visibleLayers:ArrayCollection = new ArrayCollection;
     var visibleLayers2:ArrayCollection = new ArrayCollection;
     
     // Set up map layer based on the currently selected view
     switch (cbViews.text)
     {   
      case "Annexations (City Limits)":
       lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
       visibleLayers.addItem([12]);
       lyr.alpha = 0.5;
       break;
      case "Building Inspection Areas":
       lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
       visibleLayers.addItem([2, 3]); // Only draw the inspection areas layer
       lyr.alpha = 0.5;
       break;
      case "Business Licenses":
       lyr.url = SERVER_NAME + "public/buslicense/MapServer";
       break;
      case "Cell Sites":
       lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
       lyr.alpha = 0.7;
       visibleLayers.addItem([36, 37]);
       break;
 default: // For any view not in list above
       CursorManager.removeBusyCursor();
       break;      
      }
      
      lyr.id = "viewLayer";
      lyr.addEventListener(LayerEvent.LOAD, lyrLoad);
      
      // Only draw layers added to ArrayCollection, 
      // if nothing has been added all visible layers in mxd are shown
      if (visibleLayers.length > 0){lyr.visibleLayers = visibleLayers};

      // Add layer to stack, just before parcel layer (so parcels appear on top)
      MainMap.addLayer(lyr, 1);
     
     // Add 2nd layer if it is needed    
      if (lyr2.url != null)
      {
       lyr2.id = "viewLayer2";
       if (visibleLayers2.length > 0){lyr2.visibleLayers = visibleLayers2;}
       MainMap.addLayer(lyr2, 2);      
      }

      // Move map tips layer back to top so map tips work
      MainMap.reorderLayer("MapTipsGraphicsLayer", MainMap.layers.length);
    }
 // Removes busy cursor after layer has been loaded
    private function lyrLoad(event:Event):void
    {
     CursorManager.removeBusyCursor();
    }
Tags (2)
0 Kudos
2 Replies
ThaoLe
by
Regular Contributor
Got a few questions for you

1. How do you know that it's a memory issue?
2. Is your RAM usage getting higher every time you add/remove a map layer?
3. Is ArcGIS Server and the Flex application on the same machine?
4. If so, can you reproduce the problem if the Flex application is on a different machine?
5. Have you also tried testing ArcGIS Server and the Flex application on a different machine?

If you can't reproduce the problem using different machines then more than likely the problem isn't with the API so then I would check your web server logs.
0 Kudos
BrendanLee
Emerging Contributor
Got a few questions for you

1. How do you know that it's a memory issue?
2. Is your RAM usage getting higher every time you add/remove a map layer?
3. Is ArcGIS Server and the Flex application on the same machine?
4. If so, can you reproduce the problem if the Flex application is on a different machine?
5. Have you also tried testing ArcGIS Server and the Flex application on a different machine?

If you can't reproduce the problem using different machines then more than likely the problem isn't with the API so then I would check your web server logs.


The server stops responding and we are unable to log in or reboot it. We're still troubleshooting but it seems to be a memory issue.
I've since removed all maplex labeling and have broke the largest map services into smaller ones. The maps draw much faster.

We are still having issues occassionally. It's now looking like it might be something to do with queries overloading the server.
I have a pop-up that displays info from several layers when the user does an identify. It can be up to 10 successive queries.
Is there a limit on the number of queries before you run into problems? I think I read somewhere it's 25 consecutive per second.

Everything is on the same server (data, ArcGIS Server and the flex app). We moved everything to a different sever and it happens occassionally.
0 Kudos