Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

java - does List.remove() or List.removeAll() free memory usage?

I'm processing 20GB of data inside an XML and I'm using Spring Batch to accomplish that.

I mapped my XML with Jaxb2Marshaller. This is my JAXB:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BILLSClass", propOrder = {
    "bill"
})
@XmlRootElement(name="BILLS", namespace = "http://www.amdocs.com/amdd/stp/GBF")
public class BILLSClass {

    @XmlElement(name = "BILL")
    protected List<BILLClass> bill;

    public List<BILLClass> getBILL() {
        if (bill == null) {
            bill = new ArrayList<BILLClass>();
        }
        return this.bill;
    }
}

And this BILL have many objects inside. Approximately each BILL has almost 1GB of data.

Well, I'm processing this huge XML in this way

public void processXML(BILLSClass billsClass){

    Iterator<BILLClass> iterator = billsClass.getBILL().iterator();

    while (iterator.hasNext()) {
        BILLClass bill = iterator.next();
        processBill(bill);
        billsClass.getBILL().remove(bill);
    }

}

Notice that after I call processBill(bill) inside the while, I remove the bill object I have just processed out of the billClass.

I want to know if the billsClass.getBILL().remove(bill) will decrease the memory usage in the process or do I have to do something else in order to reduce the consumption of memory.

question from:https://stackoverflow.com/questions/65851079/does-list-remove-or-list-removeall-free-memory-usage

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...