Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Processing 2.0b8 / Disposing PGraphics objects and memory management

$
0
0
Thx PhiLho for your reply, I had already checked that thread and another one where you posted your solution, but unfortunately that doesn't work with me.

I don't know if I'm going something very dumb here, but the same code works great on 1.5.1

My setup: I've a class where I create a text (quite big), than I wrote that text in a PGraphics object.
In the main draw, I'm only calling the drawWord() method that moves horizontally that object.
I'm a creating new words every 10 second. Every time a word is created, a huge amount of memory is allocated and never released.
Here is the code of my class, if you want to have a look

  1. class SingleWord {

  2. int WORD_SIZE = 100;
  3. int wordWitdh;
  4. int wordHeight;
  5. PFont wordFont;
  6. PImage wordImage;
  7. PGraphics wordImageBuffer;
  8. float wordImagePosX = 0;
  9. int wordImagePosY = 30 + (int)random(200);
  10. float speed = 0.5 + random(1);
  11. Boolean isStillOnScreen = true;

  12. SingleWord (String s) {
  13. wordFont = loadFont("FrutigerLT-LightCn-100.vlw");
  14. WORD_SIZE = 100;
  15. speed = 3;
  16. textFont (wordFont, WORD_SIZE);
  17.                wordWitdh = (int)textWidth (s);
  18.                 wordHeight = (int)(WORD_SIZE * 0.75);


  19.             int numLines = 1;
  20.    if (wordWitdh > 400) {
  21.     numLines += wordWitdh / 400;
  22.     wordWitdh = 400;
  23.    }
  24.    wordHeight = (int)(WORD_SIZE * 0.75);


  25.    wordImageBuffer = createGraphics(wordHeight*numLines + (int)(WORD_SIZE*0.25)*numLines + (numLines-1)*(int)(WORD_SIZE*0.25), wordWitdh);
  26. wordImageBuffer.beginDraw();
  27.    wordImageBuffer.fill (255, 255, 255);
  28. wordImageBuffer.textFont (wordFont, WORD_SIZE);
  29. wordImageBuffer.pushMatrix ();
  30. wordImageBuffer.translate (wordImageBuffer.width, 0);
  31. wordImageBuffer.rotate (90*3.14/180);
  32. wordImageBuffer.textAlign(CENTER);
  33.    wordImageBuffer.text(s, 0, 0, wordImageBuffer.height, wordImageBuffer.width); 
  34.    wordImageBuffer.popMatrix();
  35.    wordImageBuffer.endDraw ();

  36.   wordImage = wordImageBuffer.get (0,0, wordImageBuffer.width, wordImageBuffer.height);
  37. }




  38. void drawWord () {

  39. if (wordImagePosX < 2720) {
  40.     image (wordImage, wordImagePosX, wordImagePosY);
  41. }

  42. else {
  43. isStillOnScreen = false;
  44.                         // HERE I WOULD LIKE TO REMOVE THE RESOURCE
  45.                         // cause the word it is out of the screen
  46.                         
  47. }
  48. }
  49. }

      Any help would be really appreciated, I'm quite lost right now :(

Viewing all articles
Browse latest Browse all 1768

Trending Articles