How to release un used memory imediately RRS feed

  • Question

  • Hi all,

    i have used CLR profiler, .net memory profiler and ANTS profiler. In al these profiler if i take/collect snapshots all un used memory will be removed and my application memory usage in task manaer will reduce imediately.

    but when i run my application and write


    it has no effect on mem usage in task manager even for a long hours.

    i have a simple class and loading datatable with 2 lakh rows with 15 datacolumns of type string. once datarows is added to datatabe am using


    datatable = null; and GC.Collect();

    i would like to know how we can able to release un used memory imediately like how CLR/dot net memory profilers are doing and what will be the impact.

    please suggest me on this.

    vinaya kumar

    Thursday, June 7, 2012 1:27 PM


  • There are thousands of articles if you search for -memory manangement  in .NET- so look at those.

    Simplifying a bit, the short answer to your question is that memory in NET is basically in a chunk of memory in your process and objects use that memory. When an object in that chunk is not used it will be made available, but the size of that chunk of memory will not get smaller. For example, if your NET objects are all in a chunk if 20MB, there is still 20MB in use whether the chunk is 60% full or 80% full of objects. 

    I think CLR profilers use the CLR profiling interfaces, and I do not believe they are NET code.  C++ can alocate and release memory explicitly.

    Phil Wilson

    • Proposed as answer by Mike Feng Friday, June 8, 2012 9:50 AM
    • Marked as answer by Mike Feng Monday, June 18, 2012 1:43 PM
    Thursday, June 7, 2012 10:47 PM