visual studio 2012 - How keep the memory clear in the C# applications (DataTable dispose)? -


Is the best way to set up a DataTable and clear all the RAM memory related to the C # application? I have a simple code using {vDT} {vDT} using {DataTable vDTsec = New DataTable ()):

  Private Zero Form 1_load (Object Sender, EventAgds E) {Datatale vDT = New DataTable ()). Columns.Add ('A'); VDT.Columns.Add ("B"); VDT.Columns.Add ("B_1"); VDTsec.Columns.Add ('A'); VDTsec.Columns.Add ("B"); VDTsec.Columns.Add ("e"); (Int x = 1; x & lt; = 1000000; x ++) {vDT.Rows.Add (New object [] {x, "B" + x.ToString (), "C" + x.ToString ()}); VDTsec.Rows.Add (new object [] {x, "B" + x.ToString (), "E" + x.ToString ()}); } VDT.Dispose (); VDTsec.Dispose (); } Gc. Compiler (); GC.WaitForFullGCApproach (100); GC.WaitForPendingFinalizers (); }  

If I place a breakpoint before creating millions of rows then the application size is ~ 4MB:

after the construction of the lines, there has been a huge increase in memory (~ 428 MB):

Despite the disposal of both tables, the memory continues in 428MB:

First of all, you do not necessarily want to know about that number It should be seen in the Task Manager. This means that the garbage collector has not yet collected the memory (or the OS is caching the memory), and if the OS does not need it, then GC will collect it a little Late can wait.

The only compelling reason for better control of memory usage (beyond sensible object management) in your application is to improve the performance characteristics of your program. The way you do this, by using it, which basically means, instead of destroying and rebuilding objects, you make them once, and then use them again, so GC never Does not collect, but only use it if you have finished all other techniques to improve performance.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -