I have written a small Java program where I create 10 String Objects.
Can someone explain or answer the following questions.
- What are the best practices to create a Object. ie; When I create a Object should I also make sure I delete the object once its used. If, How do I delete it?
- If I don't delete the object, is that the object will be lying until the program ends?
- Is there a way to check the number of active objects when a program is running?
public class Test{
static public void main(String[] args){
for (Integer i = 0; i < 10; i ++){
String s1 = new String("Creating new String");
}
System.out.println("Program COmpleted");
}
}