# ShapeFileFeatureLayer.Open

**URL:** <https://community.thinkgeo.com/t/shapefilefeaturelayer-open/3029>\
**Category:** WPF\
**Created:** [July 12, 2011, 8:48pm UTC](https://community.thinkgeo.com/t/shapefilefeaturelayer-open/3029 "2011-07-12T20:48:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/3da27b/32.png) [@Ryan1](https://community.thinkgeo.com/u/Ryan1)\
**Post date:** [July 12, 2011, 8:48pm UTC](https://community.thinkgeo.com/t/shapefilefeaturelayer-open/3029/1 "2011-07-12T20:48:42Z")

</div>

Hi,

I've&nbsp;been&nbsp;doing&nbsp;a&nbsp;lot&nbsp;of&nbsp;performance&nbsp;profiling&nbsp;on&nbsp;my&nbsp;app&nbsp;recently.&nbsp;&nbsp;We&nbsp;have&nbsp;a&nbsp;lot&nbsp;of&nbsp;shapefiles&nbsp;we&nbsp;display,&nbsp;and&nbsp;when&nbsp;the&nbsp;data&nbsp;is&nbsp;not&nbsp;cached,&nbsp;the&nbsp;load&nbsp;times&nbsp;were&nbsp;unusably&nbsp;slow.&nbsp;&nbsp;Doing&nbsp;some&nbsp;profiling,&nbsp;I&nbsp;found&nbsp;that&nbsp;42%&nbsp;of&nbsp;the&nbsp;time&nbsp;was&nbsp;spent&nbsp;in&nbsp;Layer.Open(),&nbsp;and&nbsp;I&nbsp;also&nbsp;found&nbsp;that&nbsp;it&nbsp;was&nbsp;being&nbsp;opened&nbsp;and&nbsp;closed&nbsp;every&nbsp;time&nbsp;the&nbsp;layer&nbsp;was&nbsp;drawn.&nbsp;&nbsp;I&nbsp;overrode&nbsp;ShapeFileFeatureLayer&nbsp;to&nbsp;always&nbsp;keep&nbsp;the&nbsp;layer&nbsp;open&nbsp;and&nbsp;found&nbsp;that&nbsp;I&nbsp;got&nbsp;something&nbsp;like&nbsp;600%&nbsp;performance&nbsp;gain.

My&nbsp;question&nbsp;is,&nbsp;what&nbsp;if&nbsp;any&nbsp;side&nbsp;affects&nbsp;will&nbsp;I&nbsp;see&nbsp;from&nbsp;keeping&nbsp;the&nbsp;layer&nbsp;open.&nbsp;&nbsp;This&nbsp;is&nbsp;just&nbsp;base&nbsp;map&nbsp;data&nbsp;and&nbsp;will&nbsp;never&nbsp;be&nbsp;changed&nbsp;or&nbsp;queried.

&nbsp;

Thanks,

.Ryan.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 13, 2011, 10:48am UTC](https://community.thinkgeo.com/t/shapefilefeaturelayer-open/3029/2 "2011-07-13T10:48:05Z")

</div>

Ryan,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;information,&nbsp;I&nbsp;just&nbsp;curious&nbsp;that&nbsp;how&nbsp;do&nbsp;you&nbsp;override&nbsp;ShapeFileFeatureLayer&nbsp;to&nbsp;always&nbsp;keep&nbsp;the&nbsp;layer&nbsp;open,&nbsp;could&nbsp;you&nbsp;provide&nbsp;the&nbsp;code&nbsp;to&nbsp;us?&nbsp;I&nbsp;think&nbsp;it&nbsp;will&nbsp;help&nbsp;us&nbsp;optimize&nbsp;MapSuite&nbsp;to&nbsp;make&nbsp;performance&nbsp;better.&nbsp;  
&nbsp;The&nbsp;side&nbsp;effect&nbsp;is&nbsp;that&nbsp;the&nbsp;memory&nbsp;usage&nbsp;is&nbsp;very&nbsp;high,&nbsp;if&nbsp;the&nbsp;total&nbsp;shp&nbsp;files’&nbsp;size&nbsp;is&nbsp;large&nbsp;enough,&nbsp;it&nbsp;will&nbsp;throw&nbsp;Out&nbsp;Of&nbsp;Memory&nbsp;exception.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;James&nbsp;

---

<div class="post-metadata">

**Author:** ![Ryan1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/3da27b/32.png) [@Ryan1](https://community.thinkgeo.com/u/Ryan1)\
**Post date:** [July 13, 2011, 3:27pm UTC](https://community.thinkgeo.com/t/shapefilefeaturelayer-open/3029/3 "2011-07-13T15:27:47Z")

</div>

Hi&nbsp;James,&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;response.&nbsp;&nbsp;I’ve&nbsp;run&nbsp;my&nbsp;application&nbsp;for&nbsp;a&nbsp;while&nbsp;and&nbsp;have&nbsp;watched&nbsp;the&nbsp;memory&nbsp;and&nbsp;it&nbsp;seems&nbsp;to&nbsp;remain&nbsp;constant&nbsp;(it&nbsp;may&nbsp;go&nbsp;up&nbsp;100k,&nbsp;but&nbsp;the&nbsp;GC&nbsp;runs&nbsp;and&nbsp;it&nbsp;drops&nbsp;back&nbsp;down)…&nbsp;this&nbsp;is&nbsp;the&nbsp;same&nbsp;behavior&nbsp;that&nbsp;I&nbsp;was&nbsp;seeing&nbsp;before&nbsp;my&nbsp;change,&nbsp;so&nbsp;I’m&nbsp;not&nbsp;seeing&nbsp;the&nbsp;high&nbsp;memory&nbsp;usage.&nbsp;&nbsp;The&nbsp;following&nbsp;is&nbsp;my&nbsp;code&nbsp;that&nbsp;I&nbsp;use:&nbsp;  
&nbsp;&nbsp;  
&nbsp;`    public class MyShapeFileFeatureLayer : ShapeFileFeatureLayer    {        public MyShapeFileFeatureLayer(string x)            : base(x)        {        }        public MyShapeFileFeatureLayer(string x, string y)            : base(x, y)        {        }        private bool opened = false;        protected override void OpenCore()        {            if (!opened)            {                base.OpenCore();                opened = true;            }        }        protected override void CloseCore()        {            // Do nothing            //base.CloseCore();        }    } `

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 14, 2011, 10:58am UTC](https://community.thinkgeo.com/t/shapefilefeaturelayer-open/3029/4 "2011-07-14T10:58:36Z")

</div>

Ryan,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;think&nbsp;there&nbsp;are&nbsp;two&nbsp;reasons&nbsp;you&nbsp;get&nbsp;that&nbsp;result.&nbsp;&nbsp;  
&nbsp;1,&nbsp;your&nbsp;shape&nbsp;file&nbsp;is&nbsp;not&nbsp;big&nbsp;enough&nbsp;  
&nbsp;2,&nbsp;you&nbsp;only&nbsp;load&nbsp;that&nbsp;shape&nbsp;file&nbsp;for&nbsp;one&nbsp;time,&nbsp;you&nbsp;can&nbsp;try&nbsp;to&nbsp;add&nbsp;map&nbsp;to&nbsp;a&nbsp;content&nbsp;control,&nbsp;add&nbsp;content&nbsp;control&nbsp;to&nbsp;main&nbsp;form&nbsp;to&nbsp;show&nbsp;map,&nbsp;and&nbsp;then&nbsp;remove&nbsp;it,&nbsp;and&nbsp;repeat&nbsp;again,&nbsp;you&nbsp;will&nbsp;see&nbsp;the&nbsp;memory&nbsp;usage&nbsp;higher&nbsp;and&nbsp;higher.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;think&nbsp;we&nbsp;should&nbsp;dispose&nbsp;the&nbsp;resource&nbsp;after&nbsp;we&nbsp;don’t&nbsp;use&nbsp;it,&nbsp;now&nbsp;we&nbsp;put&nbsp;those&nbsp;code&nbsp;in&nbsp;layer.CloseCore,&nbsp;if&nbsp;you&nbsp;do&nbsp;nothing&nbsp;to&nbsp;override&nbsp;the&nbsp;code,&nbsp;it&nbsp;will&nbsp;make&nbsp;resource&nbsp;couldn’t&nbsp;be&nbsp;disposed.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;James&nbsp;
