When is/are the best times to use the keywords "new" & "delete" in any type of programming language?
I understand how "new" & "delete" work. "new" creates a object, pointer, etc. & "delete" deletes them. But I don't use them very much cause it forces me to use pointers when its much easier to overload or create a template.
I have experience with Java & C++, so when are the best times to use these keywords in any programming language?.
There is no such thing as the best time to use those. It has to do with the design of the programming you are trying to write.
Typically you will use them when the data requirements for your program are variable enough that you need to create items on the fly. When you don't have pre-knowledge of how many things you have to manage (which, typically is in most programming).
The only obvious statement with those languages that don't have garbage collection if you use a new, make sure you have a matching delete somewhere.



There is no such thing as the best time to use those. It has to do with the design of the programming you are trying to write.
Typically you will use them when the data requirements for your program are variable enough that you need to create items on the fly. When you don't have pre-knowledge of how many things you have to manage (which, typically is in most programming).
The only obvious statement with those languages that don't have garbage collection if you use a new, make sure you have a matching delete somewhere.
References :
Add A Comment