1 2 Previous Next 16 Replies Latest reply on Aug 24, 2007 6:27 PM by 807605

    Superclass generic array keep getting garbage collected (I Think).

      Hey Guys, this is my first post and my English isn't all that great, so sorry if I do something wrong (Like posting in the wrong place for instance, is this the right place? :D).

      This is currently my problem:

      I have an abstract superclass (for Graphs) with a couple of methods and a generic array that must follow the implementation of a Node interface, it currently looks like this:

      public abstract class Graph< V , N extends Node < V > > implements Serializable {

      public N[] nodes;

      .... methods i need for every type of Graph (most of then are not abstract)

      public interface Node <V> {

      V getValue();
      void setValue(V value);
      int getID();
      void setID(int ID);
      void print();


      Then i got some (about 6 or so) subclasses of Graph with their own implementations of Node, they look kinda like this (this is the place I Actually construct the node array) :

      public class MBGraph extends Graph<BitSet[],MBNode> implements Serializable {
      public MBGraph (..., int size, ...) {
      nodes = new MBNode[size + 1];
      ... other stuff

      MBNode implements Node for some kind of value like this:

      public class MBNode implements Node<BitSet[]>, Serializable {
      ... specific methods and parameters ...

      public int getID() {
      return ID;

      public void setID(int ID) {
      this.ID = ID;

      public BitSet[] getValue() {
      return new BitSet[] {defs, cUses, pUses, refs, undefs};

      public void setValue(BitSet[] value) {
      if (value.length != 5)
      throw new RuntimeException("Conjunto de valores inv´┐Żlido");

      defs = value[0];
      cUses = value[1];
      pUses = value[2];
      refs = value [3];
      undefs = value[4];


      Everything runs nicely some times, but then there are times where I get an error like this (and yes, it happens at random places of the program, that's why I think I'm dealing with a garbage collection problem):

      Exception in thread "main" java.lang.NoSuchFieldError: nodes
      at br.usp.each.mb.MBGraph.<init>(MBGraph.java:57)
      at br.usp.each.mb.SubsumptionGraph.setGrafo(SubsumptionGraph.java:73)
      at br.usp.each.mb.SubsumptionGraph.<init>(SubsumptionGraph.java:41)
      at br.usp.each.mb.TesteSubsumptionGraphs.main(TesteSubsumptionGraphs.java:32)

      Line 57 is a statement that used nodes a billion times before like this
      nos[aux] = new MBNo(g.nodes[aux]);

      Funny thing is that when I call nodes just before the place where the error happens it disappears (or happens somewhere else). For example, I can put something like this close to line 57
      System.out.println(g.nodes.length); // This actually guarantees that I will not get that error again around the spot

      What am I'm doing wrong?

      I'm not destroying objects manually anywhere... Neither am I using threads.

      Shouldn't the nodes array stay in memory? I mean, subclasses of Graph are always alive, isn't it supposed to guarantee that all the superclass referenced objects remains alive?

      Thanks in advance for the help.

      Message was edited by:

      Message was edited by:
        1 2 Previous Next