# Question on InMemoryBitmapTileCache.MaximumTilesCount property

**URL:** <https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908>\
**Category:** WPF\
**Created:** [December 31, 2010, 2:03pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908 "2010-12-31T14:03:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [December 31, 2010, 2:03pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/1 "2010-12-31T14:03:03Z")

</div>

If&nbsp;I&nbsp;get&nbsp;all&nbsp;tiles&nbsp;in&nbsp;InMemoryBitmapTileCache&nbsp;as&nbsp;follows:

&nbsp;

`GetTiles(new RectangleShape(-180, 90, 180, -90)); `

&nbsp;

Should&nbsp;the&nbsp;number&nbsp;of&nbsp;tiles&nbsp;returned&nbsp;exceed&nbsp;the&nbsp;MaximumTilesCount&nbsp;value&nbsp;set&nbsp;for&nbsp;this&nbsp;cache?

Thanks.

&nbsp;

---

<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:** [January 3, 2011, 8:28pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/2 "2011-01-03T20:28:34Z")

</div>

Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yes,&nbsp;the&nbsp;return&nbsp;number&nbsp;might&nbsp;exceed&nbsp;the&nbsp;MaximumTilesCount,&nbsp;because&nbsp;there&nbsp;is&nbsp;no&nbsp;relationship&nbsp;between&nbsp;the&nbsp;return&nbsp;number&nbsp;of&nbsp;tiles&nbsp;and&nbsp;MaximumTilesCount.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;  
&nbsp;James

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [January 3, 2011, 9:14pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/3 "2011-01-03T21:14:58Z")

</div>

&nbsp;Interesting.&nbsp;&nbsp;So&nbsp;how&nbsp;exactly&nbsp;does&nbsp;this&nbsp;property&nbsp;influence&nbsp;this&nbsp;cache?&nbsp;&nbsp;

---

<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:** [January 3, 2011, 9:41pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/4 "2011-01-03T21:41:16Z")

</div>

Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;cached&nbsp;image&nbsp;will&nbsp;save&nbsp;in&nbsp;memory&nbsp;as&nbsp;a&nbsp;queue,&nbsp;when&nbsp;you&nbsp;save&nbsp;a&nbsp;new&nbsp;image,&nbsp;it&nbsp;will&nbsp;check&nbsp;the&nbsp;count&nbsp;of&nbsp;queue&nbsp;if&nbsp;it&nbsp;is&nbsp;exceed&nbsp;the&nbsp;maximum&nbsp;tiles&nbsp;count,&nbsp;it&nbsp;will&nbsp;remove&nbsp;the&nbsp;first&nbsp;tile&nbsp;at&nbsp;queue&nbsp;and&nbsp;then&nbsp;add&nbsp;new,&nbsp;this&nbsp;way&nbsp;can&nbsp;limit&nbsp;the&nbsp;memory&nbsp;usage&nbsp;to&nbsp;avoid&nbsp;the&nbsp;out&nbsp;of&nbsp;memory&nbsp;error.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;  
&nbsp;James

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [January 3, 2011, 9:56pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/5 "2011-01-03T21:56:14Z")

</div>

James,&nbsp;thanks&nbsp;for&nbsp;the&nbsp;explanation.&nbsp;&nbsp;I&nbsp;now&nbsp;understand&nbsp;how&nbsp;the&nbsp;limit&nbsp;comes&nbsp;in&nbsp;and&nbsp;I&nbsp;assume&nbsp;this&nbsp;is&nbsp;imposed&nbsp;when&nbsp;one&nbsp;calls&nbsp;TileCache.SaveTile().&nbsp;&nbsp;&nbsp;Now&nbsp;could&nbsp;you&nbsp;please&nbsp;explain&nbsp;why&nbsp;number&nbsp;of&nbsp;tiles&nbsp;returned&nbsp;from&nbsp;BitmapTileCache.GetTiles()&nbsp;could&nbsp;potentially&nbsp;be&nbsp;greater&nbsp;than&nbsp;MaximumTilesCount.&nbsp;&nbsp;Where&nbsp;are&nbsp;these&nbsp;extra&nbsp;tiles&nbsp;coming&nbsp;from?&nbsp;&nbsp;There&nbsp;was&nbsp;one&nbsp;instance&nbsp;where&nbsp;I&nbsp;had&nbsp;8192&nbsp;(or&nbsp;something&nbsp;close)&nbsp;tiles&nbsp;returned&nbsp;from&nbsp;BitmapTileCache.GetTiles()&nbsp;even&nbsp;though&nbsp;I&nbsp;had&nbsp;set&nbsp;MaximumTilesCount&nbsp;to&nbsp;100.&nbsp;&nbsp;As&nbsp;an&nbsp;aside,&nbsp;i&nbsp;am&nbsp;investigating&nbsp;why&nbsp;a&nbsp;sample&nbsp;app&nbsp;has&nbsp;its&nbsp;private&nbsp;bytes&nbsp;count&nbsp;increasing&nbsp;after&nbsp;it&nbsp;has&nbsp;been&nbsp;running&nbsp;for&nbsp;days.&nbsp;  
&nbsp;&nbsp;

---

<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:** [January 3, 2011, 11:29pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/6 "2011-01-03T23:29:01Z")

</div>

Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Tile&nbsp;is&nbsp;a&nbsp;object&nbsp;that&nbsp;contains&nbsp;Bitmap&nbsp;and&nbsp;other&nbsp;things,&nbsp;the&nbsp;MaximumTilesCount&nbsp;limits&nbsp;the&nbsp;number&nbsp;of&nbsp;bitmaps,&nbsp;you&nbsp;can&nbsp;get&nbsp;tiles&nbsp;which&nbsp;number&nbsp;is&nbsp;exceed&nbsp;MaximumTilesCount,&nbsp;but&nbsp;I&nbsp;am&nbsp;sure&nbsp;some&nbsp;of&nbsp;tile’s&nbsp;Bitmap&nbsp;is&nbsp;null,&nbsp;so&nbsp;that&nbsp;the&nbsp;memory&nbsp;is&nbsp;not&nbsp;much.&nbsp;We&nbsp;can&nbsp;do&nbsp;anything&nbsp;for&nbsp;the&nbsp;return&nbsp;number&nbsp;of&nbsp;GetTiles&nbsp;because&nbsp;it&nbsp;is&nbsp;been&nbsp;calculated&nbsp;by&nbsp;base&nbsp;class&nbsp;which&nbsp;can&nbsp;not&nbsp;according&nbsp;to&nbsp;InMemoryBitmapTileCache,&nbsp;maybe&nbsp;we&nbsp;need&nbsp;to&nbsp;change&nbsp;the&nbsp;name&nbsp;to&nbsp;MaximumBitmapsCount.&nbsp;Or&nbsp;we&nbsp;maybe&nbsp;make&nbsp;GetIntersectingCells&nbsp;method&nbsp;of&nbsp;Matrix&nbsp;to&nbsp;virtual&nbsp;so&nbsp;that&nbsp;you&nbsp;can&nbsp;override&nbsp;it&nbsp;to&nbsp;write&nbsp;your&nbsp;own&nbsp;logic.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;  
&nbsp;James

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [January 4, 2011, 9:40am UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/7 "2011-01-04T09:40:01Z")

</div>

&nbsp;James,&nbsp;

I&nbsp;do&nbsp;not&nbsp;understand&nbsp;what&nbsp;you&nbsp;mean&nbsp;by&nbsp;"&nbsp;the&nbsp;MaximumTilesCount&nbsp;limits&nbsp;the&nbsp;number&nbsp;of&nbsp;bitmaps,&nbsp;you&nbsp;can&nbsp;get&nbsp;tiles&nbsp;which&nbsp;number&nbsp;is&nbsp;exceed&nbsp;MaximumTilesCount".&nbsp;&nbsp;Could&nbsp;you&nbsp;please&nbsp;clarify.

In&nbsp;response&nbsp;to&nbsp;"&nbsp;but&nbsp;I&nbsp;am&nbsp;sure&nbsp;some&nbsp;of&nbsp;tile's&nbsp;Bitmap&nbsp;is&nbsp;null,&nbsp;so&nbsp;that&nbsp;the&nbsp;memory&nbsp;is&nbsp;not&nbsp;much":&nbsp;&nbsp;If&nbsp;the&nbsp;Tile's&nbsp;Bitmap&nbsp;is&nbsp;null,&nbsp;why&nbsp;keep&nbsp;it&nbsp;in&nbsp;memory&nbsp;and&nbsp;return&nbsp;it&nbsp;as&nbsp;part&nbsp;of&nbsp;GetTiles()?&nbsp;&nbsp;

I&nbsp;am&nbsp;still&nbsp;not&nbsp;convinced&nbsp;that&nbsp;GetTiles()&nbsp;has&nbsp;no&nbsp;relationship&nbsp;to&nbsp;MaximumTilesCount&nbsp;even&nbsp;if&nbsp;it&nbsp;is&nbsp;being&nbsp;computed&nbsp;from&nbsp;BitmapTileCache.&nbsp;&nbsp;&nbsp;Sounds&nbsp;to&nbsp;me&nbsp;like&nbsp;InMemoryBitmapTileCache&nbsp;is&nbsp;returning&nbsp;the&nbsp;tiles&nbsp;even&nbsp;though&nbsp;we&nbsp;are&nbsp;calling&nbsp;GetTiles&nbsp;on&nbsp;BitmapTileCache.&nbsp;&nbsp;If&nbsp;this&nbsp;assumption&nbsp;is&nbsp;correct,&nbsp;I&nbsp;still&nbsp;do&nbsp;not&nbsp;see&nbsp;how&nbsp;number&nbsp;of&nbsp;tiles&nbsp;returned&nbsp;from&nbsp;GetTiles&nbsp;will&nbsp;exceed&nbsp;MaximumTilesCount.&nbsp;

Just&nbsp;so&nbsp;you&nbsp;have&nbsp;more&nbsp;context&nbsp;on&nbsp;this,&nbsp;I&nbsp;have&nbsp;a&nbsp;custom&nbsp;overlay&nbsp;that&nbsp;was&nbsp;put&nbsp;together&nbsp;by&nbsp;Howard.&nbsp;&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;see&nbsp;if&nbsp;it&nbsp;is&nbsp;part&nbsp;of&nbsp;my&nbsp;memory&nbsp;leak&nbsp;as&nbsp;it&nbsp;heavily&nbsp;uses&nbsp;InMemoryBitmapTileCache.&nbsp;&nbsp;

Thanks&nbsp;again.

&nbsp;

---

<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:** [January 5, 2011, 1:29am UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/8 "2011-01-05T01:29:32Z")

</div>

Hi&nbsp;Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;MaximumTilesCount&nbsp;property&nbsp;decides&nbsp;how&nbsp;much&nbsp;memory&nbsp;space&nbsp;the&nbsp;InMemoryBitmapTileCache&nbsp;is&nbsp;going&nbsp;to&nbsp;consume.&nbsp;That&nbsp;is&nbsp;its&nbsp;one&nbsp;and&nbsp;only&nbsp;mission.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Let’s&nbsp;say&nbsp;we&nbsp;have&nbsp;an&nbsp;instance&nbsp;of&nbsp;InMemoryBitmapTileCache&nbsp;which&nbsp;is&nbsp;associated&nbsp;with&nbsp;a&nbsp;LayerOverlay,&nbsp;and&nbsp;the&nbsp;MaximumTilesCount&nbsp;property&nbsp;is&nbsp;set&nbsp;to&nbsp;a&nbsp;small&nbsp;number&nbsp;(which&nbsp;is&nbsp;definitely&nbsp;not&nbsp;large&nbsp;enough&nbsp;to&nbsp;satisfy&nbsp;the&nbsp;LayerOverlay’s&nbsp;needs).&nbsp;  
&nbsp;&nbsp;  
&nbsp;When&nbsp;the&nbsp;LayerOverlay&nbsp;tries&nbsp;to&nbsp;redraw&nbsp;itself,&nbsp;it&nbsp;calls&nbsp;the&nbsp;InMemoryBitmapTileCache.GetTiles&nbsp;method&nbsp;and&nbsp;passes&nbsp;in&nbsp;a&nbsp;rectangle&nbsp;(let’s&nbsp;assume&nbsp;this&nbsp;rectangle&nbsp;is&nbsp;very&nbsp;large).&nbsp;This&nbsp;method&nbsp;will&nbsp;return&nbsp;all&nbsp;the&nbsp;tiles&nbsp;inside&nbsp;the&nbsp;rectangle,&nbsp;but&nbsp;only&nbsp;those&nbsp;tiles&nbsp;that&nbsp;are&nbsp;currently&nbsp;cached&nbsp;in&nbsp;memory&nbsp;have&nbsp;a&nbsp;valid&nbsp;bitmap,&nbsp;other&nbsp;tiles&nbsp;are&nbsp;just&nbsp;blank.&nbsp;  
&nbsp;Then&nbsp;the&nbsp;LayerOverlay&nbsp;loops&nbsp;through&nbsp;the&nbsp;returned&nbsp;tiles&nbsp;and&nbsp;fill&nbsp;those&nbsp;blank&nbsp;tiles.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Hope&nbsp;this&nbsp;explanation&nbsp;can&nbsp;clarify&nbsp;things&nbsp;up&nbsp;a&nbsp;little&nbsp;bit.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [January 5, 2011, 9:37am UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/9 "2011-01-05T09:37:42Z")

</div>

&nbsp;Tsui,&nbsp;I&nbsp;am&nbsp;getting&nbsp;there....let&nbsp;us&nbsp;use&nbsp;some&nbsp;concrete&nbsp;numbers.

Say&nbsp;I&nbsp;set&nbsp;MaximumTilesCount&nbsp;to&nbsp;100.&nbsp;&nbsp;&nbsp;If&nbsp;you&nbsp;ask&nbsp;me&nbsp;what&nbsp;this&nbsp;means,&nbsp;I&nbsp;would&nbsp;say&nbsp;100&nbsp;tiles&nbsp;is&nbsp;the&nbsp;maximum&nbsp;number&nbsp;of&nbsp;valid&nbsp;tiles&nbsp;(tiles&nbsp;with&nbsp;a&nbsp;Bitmap)&nbsp;that&nbsp;can&nbsp;be&nbsp;stored&nbsp;in&nbsp;memory&nbsp;by&nbsp;this&nbsp;cache.&nbsp;&nbsp;If&nbsp;we&nbsp;add&nbsp;more&nbsp;tiles&nbsp;to&nbsp;the&nbsp;cache,&nbsp;it&nbsp;will&nbsp;remove&nbsp;as&nbsp;many&nbsp;as&nbsp;it&nbsp;needs&nbsp;to&nbsp;maintain&nbsp;the&nbsp;maximum&nbsp;count&nbsp;of&nbsp;100.&nbsp;&nbsp;I&nbsp;understand&nbsp;the&nbsp;InMemoryBitmapTileCache&nbsp;does&nbsp;this&nbsp;is&nbsp;a&nbsp;FIFO&nbsp;manner,&nbsp;so&nbsp;oldest&nbsp;tiles&nbsp;are&nbsp;removed&nbsp;first.&nbsp;&nbsp;

Continuing&nbsp;with&nbsp;your&nbsp;example,&nbsp;say&nbsp;when&nbsp;LayerOverlay&nbsp;attempts&nbsp;to&nbsp;redraw,&nbsp;it&nbsp;calls&nbsp;InMemoryBitmapCache.GetTiles()&nbsp;passing&nbsp;in&nbsp;a&nbsp;rectangle.&nbsp;&nbsp;If&nbsp;I&nbsp;understand&nbsp;you&nbsp;correctly,&nbsp;&nbsp;if&nbsp;the&nbsp;rectangle's&nbsp;bounding&nbsp;box&nbsp;covers&nbsp;all&nbsp;the&nbsp;tiles&nbsp;currently&nbsp;held&nbsp;by&nbsp;the&nbsp;cache,&nbsp;the&nbsp;call&nbsp;to&nbsp;GetTiles&nbsp;could&nbsp;return&nbsp;X&nbsp;number&nbsp;of&nbsp;tiles&nbsp;where&nbsp;X&nbsp;is&nbsp;potentially&nbsp;greater&nbsp;than&nbsp;100.&nbsp;&nbsp;Of&nbsp;these&nbsp;X&nbsp;tiles&nbsp;returned&nbsp;100&nbsp;will&nbsp;have&nbsp;a&nbsp;&nbsp;valid&nbsp;Bitmap,&nbsp;as&nbsp;they&nbsp;came&nbsp;from&nbsp;the&nbsp;cache&nbsp;while&nbsp;the&nbsp;bitmap&nbsp;of&nbsp;&nbsp;X&nbsp;-&nbsp;100&nbsp;tiles&nbsp;will&nbsp;have&nbsp;to&nbsp;be&nbsp;created&nbsp;on&nbsp;the&nbsp;fly.&nbsp;&nbsp;Is&nbsp;this&nbsp;correct?&nbsp;&nbsp;If&nbsp;so,&nbsp;&nbsp;your&nbsp;documentation&nbsp;for&nbsp;BitmapTileCache.GetTiles()&nbsp;needs&nbsp;to&nbsp;be&nbsp;updated&nbsp;to&nbsp;reflect&nbsp;the&nbsp;fact&nbsp;that&nbsp;this&nbsp;method&nbsp;returns&nbsp;all&nbsp;tiles&nbsp;that&nbsp;intersect&nbsp;with&nbsp;the&nbsp;provided&nbsp;rectangle's&nbsp;bounding&nbsp;box,&nbsp;some&nbsp;of&nbsp;which&nbsp;may&nbsp;not&nbsp;be&nbsp;from&nbsp;the&nbsp;cache.&nbsp;&nbsp;

&nbsp;

&nbsp;

---

<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:** [January 5, 2011, 7:54pm UTC](https://community.thinkgeo.com/t/question-on-inmemorybitmaptilecache-maximumtilescount-property/2908/10 "2011-01-05T19:54:15Z")

</div>

Bingo.&nbsp;  
&nbsp;You&nbsp;got&nbsp;it&nbsp;all&nbsp;right,&nbsp;Klaus.&nbsp;  
&nbsp;And&nbsp;thank&nbsp;you&nbsp;for&nbsp;reminding&nbsp;us&nbsp;that&nbsp;the&nbsp;documentation&nbsp;of&nbsp;the&nbsp;GetTiles&nbsp;method&nbsp;is&nbsp;not&nbsp;clear&nbsp;enough.&nbsp;We’ll&nbsp;update&nbsp;it&nbsp;lately&nbsp;and&nbsp;it’ll&nbsp;be&nbsp;available&nbsp;for&nbsp;both&nbsp;the&nbsp;wiki&nbsp;site&nbsp;and&nbsp;the&nbsp;daily&nbsp;build&nbsp;package.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Tsui
