[mapguide-users] RE: featureService.SelectFeatures and
memory consumption
Vaidas Velutis
vaidas at infoera.lt
Wed Aug 18 01:43:33 EDT 2010
Thanks for sharing, but this does not help i even cant see difference that
it would use less memory L memory increases only then when i call
selectfeatures, use of other mapguide objects does not increase memory so i
think Garbage Collector does its job good. Mayby this is FDO provider bug?
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Pietro
Ianniello
Sent: Tuesday, August 17, 2010 12:47 PM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] RE: featureService.SelectFeatures and memory
consumption
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20100818/4c2f051c/attachment.html
More information about the mapguide-users
mailing list