(Solved) textureState.deleteAll(true); nullpointerexception

Hi I have a problem with memory leaks.

I create a lot of Quads and load and set an individual texture to each,

attach them to a Node "quadsNode" , which is attached to rootNode,

I also put them in a Vector "quads".

Then at some point I need to remove all Quads so I detachAllChildren() on quadsNode and do quads.clear();

Then I start creating the quads again and so on.

Everytime I do this the memory usage increases until I get OutOfMemoryError.

I read that Textures are cached so I tried the Prisms TextureCleanup:

public class TextureCleanup {

   private static TextureState ts;
   public static void cleanTexture(Spatial s) {
      ts = (TextureState)s.getRenderState(RenderState.RS_TEXTURE);
      if(ts != null)
      if(s instanceof Node) {
         ArrayList<Spatial> children = ((Node)s).getChildren();
         if(children != null) {
            Iterator i = children.iterator();
            while(i.hasNext()) {
      ts = null;

But I get NullPointerException on ts.deleteAll(true); which is strange since it's checked if null first.

These actions are triggered from a SwingUI though.

Does this have to be done in the GL thread?

Does this have to be done in the GL thread?


Thanks. Should have checked it before but I kind of realized it at the end of the post.  ://