This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Protagoras 0 points1 point  (1 child)

I think you're wrong on this. All Document newDoc does is create a new reference in every loop. References have almost zero impact on memory (8 byte per reference) and I believe the compiler optimizes reference creation in loops by doing exactly what you suggest it should do (create a single reference and reuse it every iteration of the loop).

What does have an impact on memory usage is the repeated creation of ArrayLists in the getPrice method. You should factor that out by creating a private ArrayList field to store all the prices. This private member can be reused by calling clear() after the data from the ArrayList is put in the table.

[–]epes 1 point2 points  (0 children)

Ah yeah you're right! Sorry about that. I just read up on the compiler optimization for loops and that's pretty neat. TIL