java - LibGDX: Create and dispose ShapeRenderer in render method? -


i'm using shaperenderer object create color gradient in game (screen class). allocated memory used grow permanently until started dispose shaperenderer object after every call. how can reuse color gradient? there way paint gradient texture (only once reuse in render method)?

public void render(float deltatime) {     camera.update();     batch.setprojectionmatrix(camera.combined);      shaperenderer shaperenderer = new shaperenderer();     shaperenderer.setprojectionmatrix(camera.combined);     shaperenderer.begin(shaperenderer.shapetype.filled);     shaperenderer.rect(0, 0, screenwidth, screenheight, topcolor, topcolor, bottomcolor, bottomcolor);     shaperenderer.end();     shaperenderer.dispose();      batch.begin();     ...     batch.end(); } 

although seems have solved problem, here little note , stumbling across post similar question.

do not instantiate new objects (of type) during every run through loop, @ costs. reason experiencing slow-down because of this. every time instantiate new object , stop using it, jvm's garbage collector needs rid of object. should try reuse objects. why pools , memory management in general (these links libgdx specificially) important.

your notion make field shaperenderer one, don't forget dispose() in game's dispose() method.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -