相关文章推荐
豪气的荒野  ·  WebSocket.ReceiveAsync ...·  2 月前    · 
有腹肌的玉米  ·  Flutter ...·  3 月前    · 
温柔的上铺  ·  jquery checkbox ...·  8 月前    · 
含蓄的瀑布  ·  mysql decimal转换 ...·  1 年前    · 
I have a bufferedImage which is getting drawn to and then rendered to the screen every frame. The issue is that for some reason, when getting the graphics from it, it leaks some memory, usually about 0.1-0.2 mb per iteration.
here is some of the code I used:
// v v v v in constructor BufferedImage bi; bi= ImageLoader.gc.createCompatibleImage(Display.getWidth(), Display.getHeight(), Transparency.TRANSLUCENT); bi.setAccelerationPriority( 1 ); // ^ ^ ^ ^ in constructor public void render() { bs = display.getCanvas().getBufferStrategy(); if (bs == null) { display.getCanvas().createBufferStrategy( 3 ); return ; g = (Graphics2D)bs.getDrawGraphics(); g.clearRect( 0 , 0 , Display.getWidth(), Display.getHeight()); Graphics g2 = bi.createGraphics(); g2.clearRect( 0 , 0 , bi.getWidth(), bi.getHeight()); g2.dispose(); g.drawImage(bi, 0 , 0 ,Display.getWidth(), Display.getHeight(), null); bs.show(); bi.flush(); g.dispose(); the g is a graphics object and bs is a bufferstrategy object that comes from the canvas that is made with the JFrame.
What I have tried:
I have tried disposing of the bufferedimage's graphics, and tried to flush() the image itself, but nothing seems to fix the memory leakage
Task manager on Windows is definitely not the right tool to use. It shows you how much memory is currently available for use by your application, not how much memory your application is actually using.

What is the profiler actually pointing to as the problem? It's possible that there's a memory leak inside the BufferedImage class itself, in which case there's nothing you can do to fix it.
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •