Custom layer with frozen bitmaps

1252
2
04-02-2014 01:39 AM
Labels (1)
BjørnarSundsbø
Occasional Contributor
Hi,

I have implemented some custom layers (derived from DynamicLayer and TiledLayer). When I use many of these layers, including some existing layers in the runtime, I experience a build-up of memory, which is then garbage collected.  Sometimes the GC doesn't hit soon enough, and I get out of memory exception. I've done some research, and pinpointed the build-up to BitmapImage. If I use my custom layers inside of AcceleratedDisplayLayer, implementing the appropriate interfaces, I don't get this issue. I have tried freezing the image, but then I get an InvalidOperationException when the base class is doing cleanup of resources. It can't set the image.Source = null because the image IsFrozen.

Are there any plans to change this, or ways that I can still use frozen images? I did a sample a while ago where I converted a GDI bitmap into a bitmapsource using Interop helpers, and those I could freeze for some reason. But I found another memory leak to that, so no cigar.

Any suggestions?
0 Kudos
2 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

Could you consider running the entire map in the "accelerated display" mode? (better than just using the AcceleratedDisplayLayers group layer).

Cheers

Mike
0 Kudos
BjørnarSundsbø
Occasional Contributor
Hi Mike,

Thank you for your reply. Sadly, that is not an option at the momet. We are using complex symbology in some situations (ControlTemplates with triggers to change the appearance of the symbol) for many of the graphics layers, so that puts a stop to having the whole map accelerated. Hopefully this can change in time, but not soon.

Hopefully might have some other suggestions related to reducing memory build-up? Today I read all bytes from file (as described here), and return the BitmapSource. This is because DynamicLayer/TileLayer doesn't support FileWebRequest (any plans on supporting that?. InvalidCastException). I tried creating a small WCF Rest service to return the tile using a Url, but I have the same build up. I can reproduce the same using multiple ArcGisTiledLayer instances as well. I do realize having many base layers may not make much sense, but POI objects and other overlay information are also loaded through the same custom layer, which returns a bitmap in the same way. I suppose there is not much else you can do about cleaning up these resources? Using BitmapFrame instead of BitmapSource allows me to freeze the object, but it doesn't make any difference in regards to the build up of resources.
0 Kudos