Re: Vector Storing



On Jan 31, 2:06 am, "andrewzzz" <bugp...@xxxxxxxxx> wrote:
In a class I have to store and mantain a Vector object.
I can declare it as static, but anyway to access it I have to
initialize the Vector (new Vector()) ... so everytime I create a new
instance of this class I lose my data(??).

actual :

private static Vector dynvector;

in the constructor :

dynvector=new Vector;
dynvector.add(de);//add de to the end of the vector

What should I do to save the content of a vector ???


public class MyClass {
private static final List<MyClass> createdObjects = new
ArrayList<MyClass>();

public MyClass() {
// Can you say Memory Leak?
createdObjects.add(this);
}
}

This is probably what you wanted to do.
But, it is a bad idea. This will prevent ALL your objects from being
garbage collected, unless there is no way to reach ANY of them, and
even then its unlikely.
If this code were in a long-running application, it would eat up
memory and die.

.



Relevant Pages