469,290 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

remove the last element in the array

I came across the OutOfMemoryError so I want to remove the last element in the array testThread.
Please help because I got compilation error with testThread.removeElementAt(i)
Expand|Select|Wrap|Line Numbers
  1.       try {  
  2.              testThread[i] = new TestThread(
  3.                 testClass,testInstance,testEntry,testParameters,testStreams);
  4.        } catch(java.lang.OutOfMemoryError e){
  5.          System.gc();
  6.          System.out.println("Call gcc - In the loop I=  " + i);
  7.          testThread.removeElementAt(i);
  8.                             -------------
  9.  
Thanks.
Sep 13 '07 #1
6 14894
dmjpro
2,476 2GB
I came across the OutOfMemoryError so I want to remove the last element in the array testThread.
Please help because I got compilation error with testThread.removeElementAt(i)
Expand|Select|Wrap|Line Numbers
  1.       try {  
  2.              testThread[i] = new TestThread(
  3.                 testClass,testInstance,testEntry,testParameters,testStreams);
  4.        } catch(java.lang.OutOfMemoryError e){
  5.          System.gc();
  6.          System.out.println("Call gcc - In the loop I=  " + i);
  7.          testThread.removeElementAt(i);
  8.                             -------------
  9.  
Thanks.

Welcome to TSDN!
I think it will be....!

Expand|Select|Wrap|Line Numbers
  1. testThread[some_index].removeElementAt(i);
  2.  
Good Luck.

Kind regards,
Dmjpro.
Sep 13 '07 #2
testThread[i].removeElementAt(i);
does not work
Sep 13 '07 #3
r035198x
13,262 8TB
Welcome to TSDN!
I think it will be....!

Expand|Select|Wrap|Line Numbers
  1. testThread[some_index].removeElementAt(i);
  2.  
Good Luck.

Kind regards,
Dmjpro.

To remove the last element of an array does not make sense. You can set its value to null using
Expand|Select|Wrap|Line Numbers
  1. array[(array.length - 1)] = null;
if the array type is not primitive.

And that catch(OutOfMemoryError e) ... is not good. You cannot recover from that. That System.gc() doesn't help either.
Sep 13 '07 #4
JosAH
11,448 Expert 8TB
I came across the OutOfMemoryError so I want to remove the last element in the array testThread.
Why do you think that removing a last element from an array would help in not
being hit by an OutOfMemoryError?

kind regards,

Jos
Sep 13 '07 #5
I have to load a long list of classfile to the array (in the loop and then start to run all thread after the loading are done. I will stop loading the list when I get the OutOfMemoryError, then I need to remove few number of the last element in the array and then start to run all thread.
Sep 13 '07 #6
r035198x
13,262 8TB
I have to load a long list of classfile to the array (in the loop and then start to run all thread after the loading are done. I will stop loading the list when I get the OutOfMemoryError, then I need to remove few number of the last element in the array and then start to run all thread.
You can't recover from that error in your program.
Sep 13 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by koperenkogel | last post: by
4 posts views Thread by eksamor | last post: by
14 posts views Thread by oLgAa25 | last post: by
5 posts views Thread by junky_fellow | last post: by
11 posts views Thread by Richard Maher | last post: by
3 posts views Thread by Barkingmadscot | last post: by
6 posts views Thread by tedpottel | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.