Yes, it will create 10 new objects if called 10 times. No, this doesn't cause a memory leak1. One of the main points of working in a managed language with a garbage collector is that most of the time you don't have to think about how memory is being used2.
It's also good that each call creates a new instance of the List
- because more and more these days, you'll have multiple threads running your program and you wouldn't want two calls that happen at the same time to interfere with each other's use of list
.
1To properly be a memory leak in .NET, you need something long-lived to retain references to what should be short-lived objects, when it will never actually use those references. Local variables, such as here, have relatively short lives.
2And when you do care, you're much better off learning to use a memory profiler to see what memory is being used where.