How to properly create objects in Java dynamically?

1

I need to create quantity of components n what I do not know, if it is properly written the way I do it

public class cualquierClase{
private JTextArea textAreaTab;

private JTextArea createTextAreaTab(int row, int col, String nameTextArea){
    textAreaTab = new JTextArea(row, col);
    textAreaTab.setWrapStyleWord(true);
    textAreaTab.setSize(200, 250);
    textAreaTab.setLineWrap(true);
    textAreaTab.setForeground(Color.blue);
    textAreaTab.setEditable(false);
    textAreaTab.setName("textAreaTab_"+nameTextArea);
    if (iteradorDePrueba("textAreaTab_"+nameTextArea)) {
        boxes.add(textAreaTab);
    }
    return textAreaTab;
}

}

By passing the if it will be saved in a list in which I am storing them.

What causes me doubt is if: Does each time you call the method create a new object and keep it in memory so that it does not exceed the if?.

    
asked by Dacoso 15.05.2017 в 21:35
source

1 answer

2

It is not saved in the list but if it is returned, which indicates that possibly if it will be stored in memory depending on who receives it, additional interface objects usually require special handling because they do not release their memory with only GC

    
answered by 15.05.2017 / 21:41
source