System.OutOfMemory exception error

V

Valli

Hi,

I have created a socket application which is connected at both the end. It
receives messages from Server and sends it to its connected clients.
I receive System.OutOfMemory exception error in the statement
"Thread.Start(Args())".

Whenever a messages comes in to this process, a thread is created to send
that message out to clients. Since its a market price feed messages, number
of messages comes for a sec. Is this error occurs due to the higher number
of threads running in a system?

Can anyone explain me how to fix this Memory error or a way to manage the
threads?
 
J

Jamal

Hi, Vali

It seems each thread consumes too much memory or too many threads coming
inside



The proposal is following

1) estimate how much memory consumes each thread

2) before running new thread retrieve amount of memory still available

3) if there is still enough memory according to your criteria run the thread

4) otherwise postpone the tread (store incoming message in collection or
somewhere else (temporary File?)) for a later run



Do you have another ideas?



By the way check for memory leaks within thread.



Regards, Jamal
 
T

Tom Shelton

Hi,

I have created a socket application which is connected at both the end. It
receives messages from Server and sends it to its connected clients.
I receive System.OutOfMemory exception error in the statement
"Thread.Start(Args())".

You've most likely created to many threads... Each thread allocates a fixed
amount of stack space from the application stack.

My suggestion to you is to abandon explicit threads and move your sockets to
async. The reason for this is taht the async socket functions make use of the
windows iocompletion port facility. This gives much greater scalability then
using explicit threading....
 
V

Valli

Hi,

Thanks for your suggestions.

The memory consumption error occurs since the thread takes time to close.
The thread performs a write operation in a file. Synclock is applied on that
file. So the thread waits until the lock release. All the threads waits to
perform this write operation & therefore the thread count also increases.
This provided memory error.

I have decided to use thread pool concept now.
--
Regards
Valli

Jamal said:
Hi, Vali

It seems each thread consumes too much memory or too many threads coming
inside



The proposal is following

1) estimate how much memory consumes each thread

2) before running new thread retrieve amount of memory still available

3) if there is still enough memory according to your criteria run the
thread

4) otherwise postpone the tread (store incoming message in collection or
somewhere else (temporary File?)) for a later run



Do you have another ideas?



By the way check for memory leaks within thread.



Regards, Jamal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top