eclipse / nebula

Nebula Project
https://eclipse.org/nebula
Eclipse Public License 2.0
84 stars 98 forks source link

Resource leak in GeoMap widget when changing the tile server #517

Closed bdaum closed 7 months ago

bdaum commented 1 year ago

When setting a new tile server, the tile cache is cleared. But clearing the tile cache leaves the tile images undisposed. Overriding the clear() method in the GeoMapHelper constructor fixes the problem:

    this.cache = Collections.synchronizedMap(new LinkedHashMap<TileRef, AsyncImage>(cacheSize, 0.75f, true) {
        @Override
        protected boolean removeEldestEntry(Map.Entry<TileRef, AsyncImage> eldest) {
            boolean remove = size() > GeoMapHelper.this.cacheSize;
            if (remove) {
                eldest.getValue().dispose();
            }
            return remove;
        }

        @Override
        public void clear() {
            for (AsyncImage image : values()) {
                image.dispose();
                            }
            super.clear();
        }
    });
wimjongman commented 1 year ago

Nice catch @bdaum Are you able to create a PR?

lcaron commented 1 year ago

@bdaum feel free to ask if you need any help

bdaum commented 1 year ago

Actually there is another glitch. The cache should be cleared when the GeoMapHelper instance is disposed:

/**
 * Dispose internal data
 */
public void dispose() {
    waitBackground.dispose();
    waitForeground.dispose();
    cache.clear();
}
lcaron commented 1 year ago

Hi @bdaum

Can you provide a patch through a pull request ? Do you need some help ?