remove the last element in the array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doananh
    New Member
    • Sep 2007
    • 3

    #1

    remove the last element in the array

    I came across the OutOfMemoryErro r so I want to remove the last element in the array testThread.
    Please help because I got compilation error with testThread.remo veElementAt(i)
    Code:
    	  try {  
                 testThread[i] = new TestThread(
                    testClass,testInstance,testEntry,testParameters,testStreams);
     	  } catch(java.lang.OutOfMemoryError e){
    	     System.gc();
    	     System.out.println("Call gcc - In the loop I=  " + i);
    	     testThread.removeElementAt(i);
                                -------------
    Thanks.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by doananh
    I came across the OutOfMemoryErro r so I want to remove the last element in the array testThread.
    Please help because I got compilation error with testThread.remo veElementAt(i)
    [CODE=java]
    try {
    testThread[i] = new TestThread(
    testClass,testI nstance,testEnt ry,testParamete rs,testStreams) ;
    } catch(java.lang .OutOfMemoryErr or e){
    System.gc();
    System.out.prin tln("Call gcc - In the loop I= " + i);
    testThread.remo veElementAt(i);
    -------------
    [/CODE]
    Thanks.

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

    [code=java]
    testThread[some_index].removeElementA t(i);
    [/code]

    Good Luck.

    Kind regards,
    Dmjpro.

    Comment

    • doananh
      New Member
      • Sep 2007
      • 3

      #3
      testThread[i].removeElementA t(i);
      does not work

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by dmjpro
        Welcome to TSDN!
        I think it will be....!

        [code=java]
        testThread[some_index].removeElementA t(i);
        [/code]

        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
        [CODE=java]array[(array.length - 1)] = null;[/CODE] if the array type is not primitive.

        And that catch(OutOfMemo ryError e) ... is not good. You cannot recover from that. That System.gc() doesn't help either.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by doananh
          I came across the OutOfMemoryErro r 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 OutOfMemoryErro r?

          kind regards,

          Jos

          Comment

          • doananh
            New Member
            • Sep 2007
            • 3

            #6
            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 OutOfMemoryErro r, then I need to remove few number of the last element in the array and then start to run all thread.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by doananh
              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 OutOfMemoryErro r, 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.

              Comment

              Working...