I'm creating a chatting application in javafx. I'm displaying messages using labels and adding them in arraylist. Now i want to remove labels what should i do so that labels will be destroyed from scrollpane.
Here is code:
CONNECTION clientConnection=null;
@FXML ScrollPane chatScrollPane;
VBox chatVBox;
@FXML AnchorPane chatAnchorPane;
private List<Label> messages = new ArrayList<>();
int index = 0;
I'm adding messages like:
messages.add(new Label(m));
Should i assign new memory to messages so that garbage collector will remove labels from it?
eg?
public void clearall(){
/*for(int i=0;i<index;i++){
}*/
messages = null;
System.gc();
messages = new ArrayList<>();
index = 0;
System.out.println("cleared chat");
}