G
Guest
To take advantage of the hardware power on my company’s application server,
which has 4 CPUs and 8Gs of memory, I have created a multi-threaded
application that would simultaneously process multiple requests to generate
reports.
The main thread of the application would spawn several worker threads to
process requests and generate reports, and, at the same time, the main thread
would monitor the processing statuses of all worker threads.
To conserve memory, at the end of the class/method, which is associated with
the worker thread, GC.Collect() would be called after calling all the heavy
objects’ Dispose methods and setting them to null.
Strangely enough, just one request to generate a series of big reports could
raise OUT OF MEMORY errors.
So I converted the application to be single-threaded and process requests
one at a time. The application works fine and, at any given time, only 300 MB
of memory, at most, are used to process the very same request.
I could not help but conclude that when GC.Collect() is called from a worker
thread, no disposed memory would be re-claimed right away, unless it is
called from the main thread.
Is my conclusion correct? Or there is something else I do not know about GC
in .NET?
Thanks in advance for any help or advice.
Don Lin
which has 4 CPUs and 8Gs of memory, I have created a multi-threaded
application that would simultaneously process multiple requests to generate
reports.
The main thread of the application would spawn several worker threads to
process requests and generate reports, and, at the same time, the main thread
would monitor the processing statuses of all worker threads.
To conserve memory, at the end of the class/method, which is associated with
the worker thread, GC.Collect() would be called after calling all the heavy
objects’ Dispose methods and setting them to null.
Strangely enough, just one request to generate a series of big reports could
raise OUT OF MEMORY errors.
So I converted the application to be single-threaded and process requests
one at a time. The application works fine and, at any given time, only 300 MB
of memory, at most, are used to process the very same request.
I could not help but conclude that when GC.Collect() is called from a worker
thread, no disposed memory would be re-claimed right away, unless it is
called from the main thread.
Is my conclusion correct? Or there is something else I do not know about GC
in .NET?
Thanks in advance for any help or advice.
Don Lin