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<U> : 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<U>(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<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;"> public static explicit operator U(MGDisposable<U> 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<MgMAPGUIDECLASS> mgObj = <GET THE OBJECT UING MAPGUIDE>)<br> {<br> <br> }<br><br>and the use mgObj:<br> mgObj.Get.<METHOD>()<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">.<METHOD>()<br><br></font><font face="arial,helvetica,sans-serif">Example:<br>
<br><span style="font-family: courier new,monospace;"> using (MGDisposable<MgLayerBase> 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<MgResourceIdentifier> 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<MgLayerBase> 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<MgResourceIdentifier> 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>