Mapbox-gl-js: Use "WEBGL_lose_context" to destroy WebGL context in Map#remove

Created on 2 Jun 2016  路  8Comments  路  Source: mapbox/mapbox-gl-js

mapbox-gl-js version: 0.19.0

Chrome 50

Steps to Trigger Behavior

  1. create a map
  2. .remove() the map
  3. repeat

    Expected Behavior

No warnings or errors should occur.

Actual Behavior

After a certain number of iterations (about 10 for me) there is a warning in the console Too many active WebGL contexts. Oldest context will be lost. This error indicates that the GL context is not being cleaned up when the map is removed.

feature good first issue

Most helpful comment

For anyone who comes across this... I use a work-around to show and hide the map canvas rather than redraw the map each time and that fixed my WebGL context issues. Not perfect but acceptable in my use case.

All 8 comments

Backstory - I did some work on this back in #2019 (click through and see the "outdated diffs" for more info).

We are kind of at the mercy of the garbage collector to clean up unused webgl contexts, and that doesn't always happen immediately.

@bhousel Do you know of anything we can do in GL JS to ameliorate the situation? If not, should we close this ticket as "not actionable"?

There are delete calls we could make for the underlying resources, and that potentially-sketchy SO answer also claims that resizing the canvas to 1x1 will reduce the amount of memory it consumes until it's GC'ed... shots in the dark but worth a shot

hmm, just realized there is a WebGL extension to intentionally drop the context - that might help?

There is a related thread happening now on the webgl developers list, for anyone looking for tips on how to free up webgl contexts:

https://www.khronos.org/webgl/public-mailing-list/archives/1611/msg00013.php

For anyone who comes across this... I use a work-around to show and hide the map canvas rather than redraw the map each time and that fixed my WebGL context issues. Not perfect but acceptable in my use case.

Can you please share your workaround.

@adoming3 can you please share your workaround?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mollymerp picture mollymerp  路  3Comments

jfirebaugh picture jfirebaugh  路  3Comments

aderaaij picture aderaaij  路  3Comments

yoursweater picture yoursweater  路  3Comments

muesliq picture muesliq  路  3Comments