473,574 Members | 3,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

remove the last element in the array

3 New Member
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)
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 15141
dmjpro
2,476 Top Contributor
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)
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
doananh
3 New Member
testThread[i].removeElementA t(i);
does not work
Sep 13 '07 #3
r035198x
13,262 MVP
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(OutOfMemo ryError e) ... is not good. You cannot recover from that. That System.gc() doesn't help either.
Sep 13 '07 #4
JosAH
11,448 Recognized Expert MVP
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
Sep 13 '07 #5
doananh
3 New Member
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.
Sep 13 '07 #6
r035198x
13,262 MVP
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.
Sep 13 '07 #7

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

Similar topics

11
2730
by: koperenkogel | last post by:
Dear cpp-ians, I am working with a vector of structures. vector <meta_segment> meta_segm (2421500); and the structure look like: struct meta_segment { float id; float num;
3
3795
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method isn't working. It neither removes the item from the arraylist nor from the combobox like it's supposed to do. A couple of notes: cbx is the name of...
4
9803
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
14
3032
by: oLgAa25 | last post by:
Hello all, I am back I have this question everything compiles fine, but I just need to check for an index that is more than the array size. Although it says out of bound, but it is still deleting the last element. Can someone help please Thank you all Olga I just wanted to test my function,so don't bother with main, and print
3
1593
by: Miro | last post by:
First off...thanks in advance for getting me this far. Sorry for all these class posts but im having a heck of a time here trying to get something to work, and have finally got it to work ( yahooooo ) but i dont know why now I cant get it to work the other way. Vb 2003 Below are 2 examples. One Does not work and the other does.
5
3673
by: junky_fellow | last post by:
Hi, I discussed about this earlier as well but I never got any satisfactory answer. So, I am initiating this again. Page 84, WG14/N869 "If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the
11
4491
by: Richard Maher | last post by:
Hi, I have read many of the copius entries on the subject of IE performance (or the lack thereof) when populating Select Lists. I don't mind the insert performance so much, (I get 100x120byte rows inserted/sec up to 500, and 100rows/6secs up to 3000, which isn't great but then the Row Count is clicking away for the user to see and they...
3
5576
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to delete the lines from the log file before loading in the array took ages, i thought i would be alot quicker to put in an array and remove the unwanted...
6
5495
by: tedpottel | last post by:
Help How can I remove an item from an array, Example Array=3, array=6 array=7 array=9 Is there a way to remove a item, say index 1, so the array would now be Array=3 array=7 array=9 ?????
0
7841
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8100
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7856
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6509
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3773
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.