Search code examples
javaarraysjavabeans

How to clear(empty) a string array in java?


I am getting some details and stored in to a string array(Using getter and setter).After that i am setting it as a bean(huge amount of data is taken).To avoid heap space error i have to clear the string array everytime after setting it as a bean.Is there any methods to clear it?I am new to this enviornmentAny help will be highly appreciable....

The code is given below.....

               while ((nextLine = reader.readNext()) != null &&nextLine.length!=0) {
                   Encapsulation encap=new Encapsulation();



//         System.out.println("product name"+nextLine[1]);
                encap.setId(nextLine[0]);
                encap.setProduct_name(nextLine[1]);
                encap.setProduct_url(nextLine[6]);
                encap.setProduct_image(nextLine[3]);
                encap.setProduct_price(nextLine[5]);
                encap.setProduct_src("www.flowersuk.com");
                encap.setCountry("Uk");
                encap.setDate(myDate);
                encap.setCategory(nextLine[8]);

                cvobj.DBConnection(encap);
               //at here i need to clear the string array.
              }

Solution

  • How about just nextLine = null;? Assuming there are no other references to it left dangling, it should then be eligible for garbage collection.