Hi all,
This is something of a broad question, and I'd appreciate any experience or advice people might have.
I'm finding that the UltraGrid can sometimes consume a lot of memory. I'm loading data from raw text files (50 MB in total) and displaying the data as columns of doubles and strings in several grids. I've seen the memory usage of my program shoot up to approximately 500 MB. Memory profiling reveals that most of the data is string arrays and double arrays from the grid and its data structures (but mainly string arrays).
The grids are backed by DataTables that I generate myself.
So my question is, what would be some good advice for keeping the memory usage of the grid down?
A second question, which perhaps is outside of the scope of this forum, is what can be done to keep the memory usage of the System.Data.DataTable down. The single best thing I've found was to set the initial capacity of the table to reduce the amount of memory it allocates. Normally it seems to double the amount of rows allocated each time it runs out of memory, so setting the exact capacity from the start was a big help.
Any advice/ideas would be appreciated.
Many thanks,
Johan Nystrom
Hi !
A good way to reduce the memory usage of a dot Net application is to minimize its working set.
[DllImport("kernel32.dll", EntryPoint="SetProcessWorkingSetSize", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)] private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int maximumWorkingSetSize);
/// <summary> /// Reduce the working set size off the application to a minimum. /// </summary> public void ReduceWorkingSet() { GC.Collect(); GC.WaitForPendingFinalizers(); try { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { String name = System.Diagnostics.Process.GetCurrentProcess().ProcessName; SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } catch (Exception e) { Console.Out.WriteLine(e.Message); } }
Trimming the working set of an application will be also done by the operating system through the Minimize command from its System menu or a click on its Minimize button of the form (see: "The working set of an application is trimmed when its top-level window is minimized", http://support.microsoft.com/kb/293215/en-us)
You may also use .net memory profiler tools (like http://memprofiler.com/) for optimizing applications and finding memory leaks.
Regards,
Claus