Ryan
Ryan

Reputation: 29

Permanent memory leak when using Directory.GetDirectories and Directory.EnumerateDirectories

I've encountered an extremely weird situation where running a very simple application causes memory to be permanently lost (until the system is rebooted). Here is the code below:

List<string> list = Directory.EnumerateDirectories("G:\\Video", "*", SearchOption.AllDirectories).ToList();
List<string> list2 = Directory.EnumerateDirectories("H:\\Video", "*", SearchOption.AllDirectories).ToList();

This is all the code in the application. In these video folders, there are more folders (about 30 or so) which contain hundreds of .avi video clips. When this application is run, memory gradually decreases by about 10 MB every 30 seconds or so (so if I let it run for a couple hours, a GB or more of memory will be missing.) Although in task manager, the memory doesn't show up under this application. It actually shows no where. When stopping this application, the memory ISN'T recovered. It's like something on the computer is somehow seeing that the above code is being called and then loading the files from the above search into memory. Any ideas on what could be doing this? No other applications are running (in task manager) and visual studio isn't installed on the machine this is occuring.

Upvotes: 2

Views: 897

Answers (1)

paparazzo
paparazzo

Reputation: 45106

For grins would your try this

List<string> list = = new List<string>();
foreach(var v in  Directory.EnumerateDirectories("G:\\Video", "*", SearchOption.AllDirectories)) list.add(v.ToString());

Upvotes: 1

Related Questions