# Out of Memory Exception

**URL:** <https://community.thinkgeo.com/t/out-of-memory-exception/5619>\
**Category:** WebForms\
**Created:** [December 23, 2010, 7:18am UTC](https://community.thinkgeo.com/t/out-of-memory-exception/5619 "2010-12-23T07:18:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e9bcb4/32.png) [@Vincent](https://community.thinkgeo.com/u/Vincent)\
**Post date:** [December 23, 2010, 7:18am UTC](https://community.thinkgeo.com/t/out-of-memory-exception/5619/1 "2010-12-23T07:18:23Z")

</div>

Hi&nbsp;ThinkGeo&nbsp;Team

I&nbsp;have&nbsp;encountered&nbsp;the&nbsp;following&nbsp;problem&nbsp;after&nbsp;deploying&nbsp;my&nbsp;web&nbsp;application&nbsp;in&nbsp;the&nbsp;web&nbsp;server.&nbsp;When&nbsp;two&nbsp;connections&nbsp;occur&nbsp;concurrently&nbsp;in&nbsp;the&nbsp;web&nbsp;server&nbsp;an&nbsp;out&nbsp;of&nbsp;memory&nbsp;exception&nbsp;is&nbsp;thrown.&nbsp;And&nbsp;it&nbsp;seems&nbsp;the&nbsp;exception&nbsp;originates&nbsp;from&nbsp;generating&nbsp;cache&nbsp;images.&nbsp;See&nbsp;the&nbsp;attached&nbsp;screen&nbsp;shot&nbsp;image.

Best&nbsp;regards,

Vincent

[OutOfMemory.JPG](https://community.thinkgeo.com/uploads/default/original/1X/926af4f9ecce3f17236be431b84b8cfbe1d9e169.JPG) (57.8 KB)

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [December 23, 2010, 9:08pm UTC](https://community.thinkgeo.com/t/out-of-memory-exception/5619/2 "2010-12-23T21:08:47Z")

</div>

Hi&nbsp;Vincent,&nbsp;  
&nbsp;Yes,&nbsp;just&nbsp;as&nbsp;you&nbsp;guessed,&nbsp;it&nbsp;occurs&nbsp;from&nbsp;getting&nbsp;tiff&nbsp;image&nbsp;content.&nbsp;&nbsp;Is&nbsp;it&nbsp;possible&nbsp;to&nbsp;let&nbsp;us&nbsp;know&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;image?&nbsp;Can&nbsp;you&nbsp;have&nbsp;a&nbsp;try&nbsp;that&nbsp;changing&nbsp;the&nbsp;LibraryType&nbsp;of&nbsp;GeoTiffRasterLayer&nbsp;to&nbsp;“UnmanagedLibTiff”?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Johnny&nbsp;

---

<div class="post-metadata">

**Author:** ![Vincent](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e9bcb4/32.png) [@Vincent](https://community.thinkgeo.com/u/Vincent)\
**Post date:** [December 23, 2010, 9:47pm UTC](https://community.thinkgeo.com/t/out-of-memory-exception/5619/3 "2010-12-23T21:47:20Z")

</div>

Hi&nbsp;Johnny

Thank&nbsp;you&nbsp;for&nbsp;the&nbsp;reply.&nbsp;There&nbsp;are&nbsp;4&nbsp;tiff&nbsp;files&nbsp;with&nbsp;a&nbsp;total&nbsp;size&nbsp;of&nbsp;181MB&nbsp;combined.

Best&nbsp;Regards,

Vincent

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [December 26, 2010, 8:25pm UTC](https://community.thinkgeo.com/t/out-of-memory-exception/5619/4 "2010-12-26T20:25:04Z")

</div>

Hi&nbsp;Vincent,  
  
  
  
We&nbsp;don’t&nbsp;have&nbsp;such&nbsp;big&nbsp;tiff&nbsp;files&nbsp;to&nbsp;recreate&nbsp;your&nbsp;issue,&nbsp;sorry&nbsp;for&nbsp;the&nbsp;inconvenience.&nbsp;But&nbsp;here&nbsp;is&nbsp;a&nbsp;sample&nbsp;that&nbsp;uses&nbsp;unmanaged&nbsp;tiff&nbsp;library&nbsp;so&nbsp;that&nbsp;you&nbsp;can&nbsp;directly&nbsp;replace&nbsp;using&nbsp;your&nbsp;files&nbsp;to&nbsp;test&nbsp;the&nbsp;performance.&nbsp;On&nbsp;the&nbsp;other&nbsp;hand,&nbsp;if&nbsp;your&nbsp;file&nbsp;is&nbsp;public;&nbsp;please&nbsp;send&nbsp;us&nbsp;so&nbsp;that&nbsp;we&nbsp;can&nbsp;easily&nbsp;recreate&nbsp;your&nbsp;issue.  
  
  
  
Thanks,  
  
Howard

[Post8557.zip](https://community.thinkgeo.com/uploads/default/original/2X/8/86a3b68d96f1e9044ee6ee3227638f6cee1cd440.zip) (6.42 KB)

---

<div class="post-metadata">

**Author:** ![Vincent](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e9bcb4/32.png) [@Vincent](https://community.thinkgeo.com/u/Vincent)\
**Post date:** [December 27, 2010, 2:38am UTC](https://community.thinkgeo.com/t/out-of-memory-exception/5619/5 "2010-12-27T02:38:11Z")

</div>

Hi&nbsp;Howard

Thank&nbsp;you&nbsp;for&nbsp;the&nbsp;reply.&nbsp;I&nbsp;have&nbsp;tried&nbsp;to&nbsp;implement&nbsp;your&nbsp;suggestion&nbsp;but&nbsp;I&nbsp;am&nbsp;still&nbsp;facing&nbsp;the&nbsp;same&nbsp;problem.&nbsp;When&nbsp;there&nbsp;is&nbsp;no&nbsp;collission&nbsp;of&nbsp;more&nbsp;than&nbsp;one&nbsp;request&nbsp;in&nbsp;the&nbsp;web&nbsp;server,&nbsp;everything&nbsp;is&nbsp;working&nbsp;fine.&nbsp;But&nbsp;when&nbsp;two&nbsp;connections&nbsp;raise&nbsp;a&nbsp;request&nbsp;for&nbsp;the&nbsp;image,&nbsp;then&nbsp;the&nbsp;out&nbsp;of&nbsp;memory&nbsp;exception&nbsp;fires.

My&nbsp;application&nbsp;that&nbsp;uses&nbsp;Map&nbsp;Suite&nbsp;web&nbsp;edition&nbsp;is&nbsp;mult-user&nbsp;and&nbsp;therefore,&nbsp;one&nbsp;of&nbsp;the&nbsp;requirement&nbsp;is&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;serve&nbsp;as&nbsp;many&nbsp;users&nbsp;as&nbsp;possible&nbsp;at&nbsp;a&nbsp;time.&nbsp;Can&nbsp;you&nbsp;find&nbsp;for&nbsp;me&nbsp;a&nbsp;work&nbsp;around&nbsp;to&nbsp;this&nbsp;problem?&nbsp;Below&nbsp;is&nbsp;a&nbsp;sample&nbsp;code&nbsp;showing&nbsp;how&nbsp;I&nbsp;have&nbsp;been&nbsp;doing&nbsp;it.

` GeoTiffRasterLayer Layera = new GeoTiffRasterLayer(TiffImage);Layera.LibraryType = GeoTiffLibraryType.UnmanagedLibTiff;Layera.UpperThreshold = double.MaxValue;           Layera.LowerThreshold = 0;Layera.IsGrayscale = false;LayerOverlay dynamicOverlay = new LayerOverlay();dynamicOverlay.IsBaseOverlay = false;dynamicOverlay.Name = "Image";dynamicOverlay.TileType = TileType.MultipleTile;dynamicOverlay.Layers.Add(Layera);Map1.CustomOverlays.Add(dynamicOverlay);dynamicOverlay.ServerCache = new ServerCache(@"c:\GISImageCache\temp\img1");dynamicOverlay.GenerateCacheImages(Map1.ClientZoomLevelScales[9], Map1.CurrentExtent, Map1.MapUnit);`

Best&nbsp;Regards,

Vincent

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [December 27, 2010, 11:59pm UTC](https://community.thinkgeo.com/t/out-of-memory-exception/5619/6 "2010-12-27T23:59:35Z")

</div>

Hi&nbsp;Vincent,  
  
  
  
I&nbsp;double&nbsp;checked&nbsp;your&nbsp;code&nbsp;and&nbsp;exception;&nbsp;I&nbsp;found&nbsp;it's&nbsp;weird&nbsp;to&nbsp;throw&nbsp;this&nbsp;exception&nbsp;depending&nbsp;on&nbsp;your&nbsp;code.&nbsp;From&nbsp;your&nbsp;code;&nbsp;it&nbsp;should&nbsp;throw&nbsp;"The&nbsp;process&nbsp;cannot&nbsp;access&nbsp;the&nbsp;file&nbsp;\*&nbsp;because&nbsp;it&nbsp;is&nbsp;being&nbsp;used&nbsp;by&nbsp;another&nbsp;process.";&nbsp;because&nbsp;you&nbsp;allow&nbsp;the&nbsp;cache&nbsp;generating&nbsp;by&nbsp;different&nbsp;users.&nbsp;Actually,&nbsp;you&nbsp;only&nbsp;need&nbsp;one&nbsp;user&nbsp;to&nbsp;raise&nbsp;the&nbsp;method&nbsp;to&nbsp;generate&nbsp;the&nbsp;cache&nbsp;files&nbsp;at&nbsp;server&nbsp;side;&nbsp;once&nbsp;the&nbsp;operation&nbsp;is&nbsp;running,&nbsp;the&nbsp;other&nbsp;users&nbsp;won't&nbsp;raise&nbsp;this&nbsp;operation&nbsp;anymore.&nbsp;So&nbsp;I&nbsp;modify&nbsp;your&nbsp;code&nbsp;a&nbsp;little&nbsp;to&nbsp;fix&nbsp;this&nbsp;conflict.&nbsp;Please&nbsp;have&nbsp;a&nbsp;try.  
  
  
  
`Monitor.Enter(Application);if (Application["Caching"] == null){    Application["Caching"] = new Object();    ThreadStart threadStart = new ThreadStart(() =>    {        tiffOverlay.GenerateCacheImages(Map1.ClientZoomLevelScales[9], Map1.CurrentExtent, Map1.MapUnit);    });    Thread newThread = new Thread(threadStart);    newThread.Start();}Monitor.Exit(Application);`  
  
  
Thanks,  
  
Howard
