You should try to dispose every mapguide object.<br>I have written the following simple class not to forget any object:<br><br><span style="font-family: courier new,monospace;">---------------------------------</span><br><span style="font-family: courier new,monospace;">using System;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">using System.Collections.Generic;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using System.Linq;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">using System.Text;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">namespace MapGuideHelpers</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    //Class T[o]B[e]Disposed</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    public class MGDisposable&lt;U&gt; : IDisposable where U : OSGeo.MapGuide.MgDisposable</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        U _val;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        public U Get { get { return _val; } }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        MGDisposable(U val)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            _val = val;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        public static implicit operator MGDisposable&lt;U&gt;(U uvar)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            return new MGDisposable&lt;U&gt;(uvar);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        public static explicit operator U(MGDisposable&lt;U&gt; mgtbdvar)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            return mgtbdvar._val;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        #region disposing interface</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        public void Dispose()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            this.Dispose(true);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            GC.SuppressFinalize(this);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        ~MGDisposable()</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            this.Dispose(false);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        protected virtual void Dispose(bool disposing)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if (null != _val)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                _val.Dispose();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        #endregion</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">---------------------------------</span><br><br><font face="arial,helvetica,sans-serif">Now you can:<br>

<br>            using (MGDisposable&lt;MgMAPGUIDECLASS&gt; mgObj = &lt;GET THE OBJECT UING MAPGUIDE&gt;)<br>            {<br>                <br>            }<br><br>and the use mgObj:<br>          mgObj.Get.&lt;METHOD&gt;()<br>

or<br>          ((</font><font face="arial,helvetica,sans-serif">MgMAPGUIDECLASS</font><font face="arial,helvetica,sans-serif">)mgObj)</font><font face="arial,helvetica,sans-serif">.&lt;METHOD&gt;()<br><br></font><font face="arial,helvetica,sans-serif">Example:<br>

<br><span style="font-family: courier new,monospace;">            using (MGDisposable&lt;MgLayerBase&gt; layer = layerCollection.GetItem(i))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                using (MGDisposable&lt;MgResourceIdentifier&gt; layerDefinition = </span><i style="font-family: courier new,monospace;">layer.Get</i><span style="font-family: courier new,monospace;">.GetLayerDefinition())</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                     //...</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br></font><font face="arial,helvetica,sans-serif">Or:<br>

</font><font face="arial,helvetica,sans-serif"><span style="font-family: courier new,monospace;">            using (MGDisposable&lt;MgLayerBase&gt; layer = layerCollection.GetItem(i))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">
            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
                using (MGDisposable&lt;MgResourceIdentifier&gt; layerDefinition = <br>                                           </span><i style="font-family: courier new,monospace;">((MgLayerBase)layer)</i><span style="font-family: courier new,monospace;">.GetLayerDefinition())</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">
                {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
                     //...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
                }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
            }</span><br>
</font><br><font face="arial,helvetica,sans-serif"><br>Pietro Ianniello<br></font>