How to fix memory leak caused by PGraphics?

edited June 2017 in Questions about Code

My program uses the PGraphics object as a buffer to create graphics before drawing to the screen. After running my program for about 20 minuets it crashes. Looking at the system memory use it looks like this is caused by and out of memory error. Interestingly this seems to only happen when I build the application (not running from the editor).

After reading this post https://forum.processing.org/one/topic/pimage-memory-leak-example.html#25080000001807951 and some more that also reference the g.removeCache(img); solution I tired it out. I think it's clearing the cache, but it's causing only black to be drawn to the screen.

A section of my code:

public void drawRoute() { tint(255, myAlpha); image(myPg, 0, 0); g.removeCache(myPg); noTint(); }

I'm calling drawRoute() directly from the main draw().

What am I doing wrong? Is this fix still relevant for processing 3.3.4?

Thanks

Sign In or Register to comment.