This is a very basic question, but I thought better to ask. Let us assume I have the following code snippet.
List<String> mystringlist1 = new List<String>();
List<String> mystringlist2 = new List<String>();
mystringlist2.Add("hello1");
mystringlist2.Add("hello2");
mystringlist2.Add("hello3");
//Now I assign the second list to first list
mystringlist1 = mystringlist2;
Now as it stands, both the lists will be pointing to the same memory location and trying to access the individual elements will result in the same elements of the above list.
If so,
- what would have happened to the unclaimed/unused allocation which was done for mystringlist1?
- Will this be automatically garbage collected or will it result in memory leaks?
- Is it a bad practice to do this?