Re: Vector Storing
- From: "Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx>
- Date: 31 Jan 2007 11:00:29 -0800
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.
.
- References:
- Vector Storing
- From: andrewzzz
- Vector Storing
- Prev by Date: Re: 2D lookup table
- Next by Date: Re: Java Problem!!!
- Previous by thread: Re: Vector Storing
- Next by thread: (newbie) definitive class/regex for stripping empty lines from text files?
- Index(es):
Relevant Pages
|