|
From: Trevor S. <ts...@ty...> - 2005-04-14 15:40:36
|
On Thu, 2005-04-14 at 05:19, Oliver Meyn wrote:
> I've been working with StyledMapPanes for the last few months but only
> recently started ramping up the layers in the MapContexts I've been
> feeding to the Pane. I've narrowed the "leak" (cumulative memory usage
> within the jvm) to the setContext method of StyledMapPane, such that
> when I feed the StyledMapPane a sufficiently large MapContext as follows:
>
> MapContext map;
> /* add some layers */
>
> StyledMapPane mapPane = new StyledMapPane();
> mapPane.setMapContext(this.map);
> mapPane.setMapContext(null);
> mapPane = null;
>
> then I start losing memory. I've tried running the gc, setting the
> thread to sleep to wait for gc, both, but no joy. If I try this test
> with just an empty DefaultMapContext it works fine, but that's so little
> memory that my (rather simple) test might not reveal the flaw.
>
> Looking at the StyledMapPane code it appears that setMapContext really
> just sets the context of the Renderer in turn, but before I try to get
> deeper into that I'm hoping someone has some bright ideas as to what's
> going on and how I can fix it.
>
I noticed a similar issue a while ago while I was playing with
aerial photos. In order to prevent my application from running
out of memory, I had to do the following when I removed a coverage
layer:
if (gridCoverageIds.size() > 0) {
for (Iterator iter = coverageLayers.iterator();
iter.hasNext();) {
RenderedLayer element = (RenderedLayer) iter.next();
map.getRenderer().removeLayer(element);
element.dispose();
iter.remove();
}
gridCoverageIds.clear();
// Renderer caches both the original and projected images --
perhaps one reason it's slow
// without the belowe for loop, we get OutOfMemoryErrors
RenderedLayer[] renderedLayers =
map.getRenderer().getLayers();
for (int i = 0; i < renderedLayers.length; i++) {
if (renderedLayers[i] instanceof RenderedGridCoverage) {
map.getRenderer().removeLayer(renderedLayers[i]);
renderedLayers[i].dispose();
}
}
}
The dispose() method of RenderedLayer says "really get rid of yourself."
I haven't yet created a JIRA issue for this, but I'll be playing with
it again in the next two days and I'll report my findings (with the
help of a profiler).
--
Trevor Stone | Software Engineer | tel 800-554-4434 | fax 303-271-1930 | eMail ts...@ty...
Tyler Technologies | Eagle Division | 14142 Denver West Pkwy Suite 155 | Lakewood, CO 80401 | www.tyler-eagle.com
|