I am creating an STA thread as I am basically using a UI component within a library that has functionality I want without actually having any UI (exporting tables to Excel).
System.Threading.Thread thread = new System.Threading.Thread(() =>
{
_reportRunner.RunReport(report);
});
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();
thread.Join();
Above is where the magic happens, it runs fine however it does not dispose of the objects properly and I am getting huge memory leaks as some of these data tables are very large.
I can find various information on STA threads and memory leaks but not much on solving them, is there anyway to free up the memory, I've tried manually forcing the garbage collector but a) it doesn't work and b) I really don't want to do that.
My application is effectively a console app, no WPF in sight.
I have used dotMemory memory profiler to understand this, my app is using 8gb of memory which is meant to be released once a report is produced and exported but it is not.
I am using Dev express WPF pivotgridcontrol which has an export function