Memory usage
-
Hi! I have some questions: 1. Does anyone know how in runtime detect how many memory used by each class? 2. Does anyone know how to minimize memory usage of application (like unloading of unneeded assemblies or something else)? 3. Does anyone know any resource with "performance" + "memory usage" tests on Windows.Forms? I have such situation: I wrote application which make some automation tasks like send e-mail, generate Excel reports (office automation) and etc. Application is not too large but it’s usage of memory make customer dizzy. As you know customer dizzy become a developer soon. Now I have a great :( task to minimize memory usage of application. First of all I need to know how many each class use memory, second step rewrite code of such classes. To my opinion 30-40 Mb memory usage (on computer with 128 Mb) for garbage collector is good enough... Good Luck Alex Kucherenko
-
Hi! I have some questions: 1. Does anyone know how in runtime detect how many memory used by each class? 2. Does anyone know how to minimize memory usage of application (like unloading of unneeded assemblies or something else)? 3. Does anyone know any resource with "performance" + "memory usage" tests on Windows.Forms? I have such situation: I wrote application which make some automation tasks like send e-mail, generate Excel reports (office automation) and etc. Application is not too large but it’s usage of memory make customer dizzy. As you know customer dizzy become a developer soon. Now I have a great :( task to minimize memory usage of application. First of all I need to know how many each class use memory, second step rewrite code of such classes. To my opinion 30-40 Mb memory usage (on computer with 128 Mb) for garbage collector is good enough... Good Luck Alex Kucherenko
I don't have answers for all of your questions, but here something to get you started If you are creating COM objects then you can force their release by doing MyObject=null; System.GC.Collect(); System.GC.WaitForPendingFinalizers(); System.GC.Collect(); Be carefull when looking at memory usage in the Task Manager it isn't telling you the whole truth.:eek: To determine the real memory usage of an application you could: ' Visual Basic .NET Dim NotepadMemory as Integer Dim component1() as Process component1 = Process.GetProcessesByName("Notepad.exe") NotepadMemory = component1(0).PrivateMemorySize Console.WriteLine("Memory used: " & NotepadMemory & ".") // C# int memory; Process[] notepads; notepads = Process.GetProcessesByName("Notepad.exe"); notepadMemory = notepads[0].PrivateMemorySize; Console.WriteLine("Memory used: {0}.", notepadMemory);