Take a look at the following link: GLSurfaceView Code Example
In particular, look at the following function in the second code block on this page:
public boolean onTouchEvent(final MotionEvent event) { queueEvent(new Runnable() { public void run() { mRenderer.setColor(event.getX() / getWidth(), event.getY() / getHeight(), 1.0f); } }); return true; }
What bothers me is that anon Runnable refers to a very local event object, but queueEvent actually finishes running Runnable on a completely separate thread, and possibly long after this particular instance of the event is long dead. which is obviously a problem. Or is it that, like using local-ref-in-anon-class, it actually does +1 in the ref-count of the event object, so that it gets stuck as long as anon Runnable is still breathing?
Also, does the fact that MotionEven is declared final have anything to do with all this?
PS As a related question (although this is not my main problem), what if instead of (or in addition to) "event" we wanted to call some kind of primitive, such as "int x" inside the anon class, what happens then? (seeing that you canβt +1 the number of primitive links).
source share