You should try to dispose every mapguide object.
I have written the following simple class not to forget any object:

---------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapGuideHelpers
{
    //Class T[o]B[e]Disposed
    public class MGDisposable<U> : IDisposable where U :
OSGeo.MapGuide.MgDisposable
    {
        U _val;
        public U Get { get { return _val; } }

        MGDisposable(U val)
        {
            _val = val;
        }

        public static implicit operator MGDisposable<U>(U uvar)
        {
            return new MGDisposable<U>(uvar);
        }
        public static explicit operator U(MGDisposable<U> mgtbdvar)
        {
            return mgtbdvar._val;
        }

        #region disposing interface

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        ~MGDisposable()
        {
            this.Dispose(false);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (null != _val)
            {
                _val.Dispose();
            }
        }

        #endregion
    }
}
---------------------------------

Now you can:

            using (MGDisposable<MgMAPGUIDECLASS> mgObj = <GET THE OBJECT
UING MAPGUIDE>)
            {

            }

and the use mgObj:
          mgObj.Get.<METHOD>()
or
          ((MgMAPGUIDECLASS)mgObj).<METHOD>()

Example:

            using (MGDisposable<MgLayerBase> layer =
layerCollection.GetItem(i))
            {
                using (MGDisposable<MgResourceIdentifier> layerDefinition =
*layer.Get*.GetLayerDefinition())
                {
                     //...
                }
            }
Or:
            using (MGDisposable<MgLayerBase> layer =
layerCollection.GetItem(i))
             {
                using (MGDisposable<MgResourceIdentifier> layerDefinition =
                                           *((MgLayerBase)layer)*
.GetLayerDefinition())
                 {
                     //...
                }
            }


Pietro Ianniello
_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to