Java heap space Error

edited May 2015 in Library Questions

Ciao everyone!

I am tring to have an oc-tree from pointclouds of kinect.
Problem I had, was convert the kinect.depthMapRealWorld() that is PVector array, to a Vec3D because I am usin Toxiclibs library.
Finally I have a Vec3D array with all points inside. Now I have another big problem. If I use
tree.addAll(new ArrayList(toxVecs.length));
it draw me only one cube of the octree and not all points.
Instead if i write
for (int i = 0; i < toxVecs.length-1; i++) { tree.addPoint(toxVecs[i]); }
i receive the "Java heap error"!! toxVecs [] is my array with all pointclouds inside.

  • Any help?
  • Do you have other approach to solve this problem?

Help me please, don't leave me alone!

Thank you,
Dam

Answers

  • A heap error probably means that you're trying to create a lot of new objects. Like, a lot of them. And the computer just can't find the space to make them all. How many points are we talking about here?

  • Thank you @TfGuy44.
    Yes i soved yet yesterday incrementing the "i" steps at i+25 it works (slowly of course).

    The number of points it is about 307200.

    There is another strategy for improve the number of points and performance? A guy told me about "Multithreading". It can work?

    Thanks,
    Dam

  • edited May 2015
    • Depending on how many cores a computer got, multithreading can make a huge difference.
    • However, only sketch's "Animation" Thread should directly draw to the main canvas.
    • Others can use their own PGraphics and then having the main "Animation" Thread stamp everything into the canvas within draw().
  • thank you @GoToLoop!!

    • I have i7 with 4 core (8 virtual) and gtx 560 with CUDA;
    • can you give me some example please? because I didn t understand. I never used Thread until now..
  • edited May 2015

    Disclaimer: Threading isn't for the faint of heart! :-t

    • In Processing our whole sketch runs in a Thread called "Animation".
    • And by default, callback draw() is invoked at about frameRate(60) FPS (~ 16ms).
    • However, if the entire action takes more than that, target FPS won't be reached and get slow!
    • But if we can transfer some of that burden to another Thread we might be able to speed everything up.
    • Unfortunately we should avoid modifying sketch's canvas outside "Animation" Thread.
    • Instead we can draw into a separate PGraphics and have the main "Animation" Thread stamp it onto the canvas later.
    • In order to create a Thread, easiest way is by calling thread("") w/ the name of the function which will run by it as its String argument:
      https://processing.org/reference/thread_.html
    • Basically we got draw() running at the same time as circleThread().
    • Only draw() directly modifies the canvas while circleThread() got its own local PGraphics called pg.
    • draw() is called back @ frameRate(1) FPS while circleThread() sleeps delay(INTERVAL) milliseconds.
    • As you can see, they have 1 thing in common, a PImage variable called sharedImg!
    • Once circleThread() finishes modifying its pg, it clones it w/ get() and assigns it to sharedImg.
    • And b/c sharedImg is volatile, other threads can see that re-assignment ASAP.

    • If you wanna get deeper into threading further, it's better you open a separate "Ask a Question".

    • And Oracle got some tutorials about it here:
      http://docs.oracle.com/javase/tutorial/essential/concurrency/index.html

    /**
     * PGraphics Threading (v1.0)
     * by GoToLoop (2015-May-13)
     * forum.processing.org/two/discussion/10781/java-heap-space-error
     */
    
    static final int GAP = 50, INTERVAL = 5*1000; // 5 seconds.
    
    volatile PImage sharedImg;
    
    void setup() {
      size(600, 400, JAVA2D);
    
      smooth(4);
      frameRate(1);
    
      strokeWeight(3);
      stroke(-1);
    
      rectMode(CORNER);
      background(0);
    
      thread("circleThread");
      while (sharedImg == null)  delay(10);
    }
    
    void draw() {
      frame.setTitle("FrameCount: " + frameCount);
    
      fill((color) random(#000000));
      rect(GAP, GAP, width - GAP*2, height - GAP*2);
    
      image(sharedImg, 0, 0);
    }
    
    void circleThread() {
      final PGraphics pg = createGraphics(width, height, JAVA2D);
    
      pg.beginDraw();
      pg.smooth(4);
      pg.strokeWeight(2);
      pg.stroke(0);
      pg.ellipseMode(CENTER);
    
      for (;; delay(INTERVAL)) {
        pg.fill((color) random(#000000));
        pg.ellipse(width>>1, height>>1, height>>1, height>>1);
        pg.endDraw();
    
        sharedImg = pg.get();
      }
    }
    
  • Wow! Thank you.

    It look very hard topic. I will study your message and in case I will find some problem I will open a new topic as you suggest me.

    Thank you!

Sign In or Register to comment.