> I'm trying to get my app to release some memory, as it can
> grow quite large, and throw an OutOfMemory exception.
>
> Here is a test example, the code is pretty small, but I'm
> reading a 35meg file.
>
> Here's what the code looks like:
>
>
>    byte[] data = ReadFile( ...); //memory footprint is about
> 42megs (taskman), which is acceptable
>
>    chars = Encoding.ASCII.GetChars( data ); //jumps to 115meg
> --varies a few meg depending upon the Encoding used.
>
>    data = null; //still stays at 115meg
>
>    GC.Collect();
>    GC.WaitForPendingFinalizers();
>    GC.Collect();  //memory is still at 115 meg.
>
> Is there any reason why the memory wouldn't have been
> released after calling GC.Collect()? I'm assuming calling
> GC.Collect() would have released the memory used by data.

        Please check the help on GC.Collect. It will show you that the method 
won't reclaim memory directly. No method in .NET will
reclaim memory directly, .NET has an asynchronous garbage collector.

        To properly test what the memory is of your application, please open 
performance monitor and add .NET counters for memory,
and the GC 0, 1 and 2 levels. You'll notice that once your routine has been 
completed (and execution proceeds outside the routine),
the GC will kick in, but not right away. It will kick in on regular intervals 
AND when memory pressure is high.

                FB

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to