Select to view content in your preferred language

DynamicMapService Refresh Leaking Memory

727
2
10-21-2010 10:12 AM
DougCollins
Occasional Contributor
We have found that a "Refresh" on an ArcGISDynamicMapServiceLayer causes a memory leak.  The memory consumed by the browser continues to grow each time the layer is refreshed.  This is a real problem when you are trying to monitor changes such as location or attributes for a particular layer.  The only way we have found to release the memory is to close the browser and start over, which is unacceptable to our users.

Here is some sample code that has a button to refresh a dynamic map layer from arcgisonline.  Each time you click refresh the memory grows.

XAML code below:
<UserControl x:Class="MemoryTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    mc:Ignorable="d"
    d:DesignHeight="500" d:DesignWidth="700">

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
       
        <esri:Map x:Name="MyMap" Grid.Row="1" >
           
            <!-- Background Tiled Map -->
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                  Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
           
            <!-- A Dynamic Map Service Layer -->
            <esri:ArcGISDynamicMapServiceLayer ID="DynamicLayer"
                    Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer" DisableClientCaching="True" />

        </esri:Map>
       
        <!-- Status Text Box -->
        <TextBox x:Name="Status" Width="400" Height="28" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center" />
       
        <!-- Map Refresh Button -->
        <Button x:Name="RefreshBtn" Content="Refresh" Width="60" Height="20" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center"  Click="RefreshBtn_Click" />
       
    </Grid>
</UserControl>

C# Code Behind:
namespace MemoryTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        // Code to execute when the Refresh button is clicked.
        private void RefreshBtn_Click(object sender, RoutedEventArgs e)
        {
            string msg;
            try
            {
                string serviceName = "DynamicLayer";
                ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer = MyMap.Layers[serviceName] as
                            ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;

                // Refresh the DynamicLayer - THIS is where the MEMORY LEAK occurs!!!
                dynamicServiceLayer.Refresh();

                msg = "PointLayer Refreshed at: ";
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }

            string timeStr = DateTime.Now.ToLocalTime().ToLongTimeString();
            Status.Text = msg + timeStr;
        }
    }
}

---
Is there something we need to do to release the memory each time the layer is refreshed?
Are we doing something wrong here, or is this a real bug?
Has anyone else seen this?

Thanks, we are anxious to get this resolved!

Charlie
0 Kudos
2 Replies
NoneNone
New Contributor
Same issue here.  Is that a bug?  How do we release memory with dynamic and feauture layers?
0 Kudos
JenniferNery
Esri Regular Contributor
Thank you for your feedback. We are looking into getting this fixed in future releases.
0 Kudos