If I get all tiles in InMemoryBitmapTileCache as follows:
GetTiles(new RectangleShape(-180, 90, 180, -90));
Should the number of tiles returned exceed the MaximumTilesCount value set for this cache?
Thanks.
If I get all tiles in InMemoryBitmapTileCache as follows:
GetTiles(new RectangleShape(-180, 90, 180, -90));
Should the number of tiles returned exceed the MaximumTilesCount value set for this cache?
Thanks.
Klaus,
Yes, the return number might exceed the MaximumTilesCount, because there is no relationship between the return number of tiles and MaximumTilesCount.
Thanks
James
Interesting. So how exactly does this property influence this cache?
Klaus,
The cached image will save in memory as a queue, when you save a new image, it will check the count of queue if it is exceed the maximum tiles count, it will remove the first tile at queue and then add new, this way can limit the memory usage to avoid the out of memory error.
Thanks
James
James, thanks for the explanation. I now understand how the limit comes in and I assume this is imposed when one calls TileCache.SaveTile(). Now could you please explain why number of tiles returned from BitmapTileCache.GetTiles() could potentially be greater than MaximumTilesCount. Where are these extra tiles coming from? There was one instance where I had 8192 (or something close) tiles returned from BitmapTileCache.GetTiles() even though I had set MaximumTilesCount to 100. As an aside, i am investigating why a sample app has its private bytes count increasing after it has been running for days.
Klaus,
Tile is a object that contains Bitmap and other things, the MaximumTilesCount limits the number of bitmaps, you can get tiles which number is exceed MaximumTilesCount, but I am sure some of tile’s Bitmap is null, so that the memory is not much. We can do anything for the return number of GetTiles because it is been calculated by base class which can not according to InMemoryBitmapTileCache, maybe we need to change the name to MaximumBitmapsCount. Or we maybe make GetIntersectingCells method of Matrix to virtual so that you can override it to write your own logic.
Thanks
James
James,
I do not understand what you mean by " the MaximumTilesCount limits the number of bitmaps, you can get tiles which number is exceed MaximumTilesCount". Could you please clarify.
In response to " but I am sure some of tile's Bitmap is null, so that the memory is not much": If the Tile's Bitmap is null, why keep it in memory and return it as part of GetTiles()?
I am still not convinced that GetTiles() has no relationship to MaximumTilesCount even if it is being computed from BitmapTileCache. Sounds to me like InMemoryBitmapTileCache is returning the tiles even though we are calling GetTiles on BitmapTileCache. If this assumption is correct, I still do not see how number of tiles returned from GetTiles will exceed MaximumTilesCount.
Just so you have more context on this, I have a custom overlay that was put together by Howard. I am trying to see if it is part of my memory leak as it heavily uses InMemoryBitmapTileCache.
Thanks again.
Hi Klaus,
The MaximumTilesCount property decides how much memory space the InMemoryBitmapTileCache is going to consume. That is its one and only mission.
Let’s say we have an instance of InMemoryBitmapTileCache which is associated with a LayerOverlay, and the MaximumTilesCount property is set to a small number (which is definitely not large enough to satisfy the LayerOverlay’s needs).
When the LayerOverlay tries to redraw itself, it calls the InMemoryBitmapTileCache.GetTiles method and passes in a rectangle (let’s assume this rectangle is very large). This method will return all the tiles inside the rectangle, but only those tiles that are currently cached in memory have a valid bitmap, other tiles are just blank.
Then the LayerOverlay loops through the returned tiles and fill those blank tiles.
Hope this explanation can clarify things up a little bit.
Regards,
Tsui
Tsui, I am getting there....let us use some concrete numbers.
Say I set MaximumTilesCount to 100. If you ask me what this means, I would say 100 tiles is the maximum number of valid tiles (tiles with a Bitmap) that can be stored in memory by this cache. If we add more tiles to the cache, it will remove as many as it needs to maintain the maximum count of 100. I understand the InMemoryBitmapTileCache does this is a FIFO manner, so oldest tiles are removed first.
Continuing with your example, say when LayerOverlay attempts to redraw, it calls InMemoryBitmapCache.GetTiles() passing in a rectangle. If I understand you correctly, if the rectangle's bounding box covers all the tiles currently held by the cache, the call to GetTiles could return X number of tiles where X is potentially greater than 100. Of these X tiles returned 100 will have a valid Bitmap, as they came from the cache while the bitmap of X - 100 tiles will have to be created on the fly. Is this correct? If so, your documentation for BitmapTileCache.GetTiles() needs to be updated to reflect the fact that this method returns all tiles that intersect with the provided rectangle's bounding box, some of which may not be from the cache.
Bingo.
You got it all right, Klaus.
And thank you for reminding us that the documentation of the GetTiles method is not clear enough. We’ll update it lately and it’ll be available for both the wiki site and the daily build package.
Regards,
Tsui