twc
Posts: 129
Nickname: twc
Registered: Feb, 2004
|
|
Re: reallocation of memory in Java
|
Posted: May 9, 2004 4:44 PM
|
|
> Hi, > I am just starting to learn java, though I know C++ very > good. > I would like to know how can I reallocate mem in Java. > suppose I have created an array of 10 items of class A, > and now I want to reallocate 12 items, should i just > "free" mem, by setting my array to null, and than call to > new again while allocating 12 elements ? > Is this is how it should be done in java ? > whare are my options?
You don't have to mess with reallocation in Java. That is what the garbage collector is for.
//creates an array of 10 objects.
Object[] someObject = new Object[10];
//sometime later old array is discarded, and new 12 element array is created.
someObject = new Object[12]; //Garbage collector will reallocate the memory from the discarded array. Not your problem.
|
|