Home All Groups Group Topic Archive Search About

System.OutOfMemory exception error

Author
6 Jul 2009 7:06 AM
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?

--
Regards
Valli

Author
6 Jul 2009 2:12 PM
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

Show quoteHide quote
"Valli" <va***@chellsoft.com> wrote in message
news:%23ltY7gg$JHA.1252@TK2MSFTNGP04.phx.gbl...
> 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?
>
> --
> Regards
> Valli
>
Are all your drivers up to date? click for free checkup

Author
7 Jul 2009 6:33 AM
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

Show quoteHide quote
"Jamal" <samed***@planet.nl> wrote in message
news:OdghUPk$JHA.3732@TK2MSFTNGP02.phx.gbl...
> 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
>
> "Valli" <va***@chellsoft.com> wrote in message
> news:%23ltY7gg$JHA.1252@TK2MSFTNGP04.phx.gbl...
>> 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?
>>
>> --
>> Regards
>> Valli
>>
>
>
Author
6 Jul 2009 5:09 PM
Tom Shelton
On 2009-07-06, Valli <va***@chellsoft.com> wrote:
> 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....

--
Tom Shelton

Bookmark and Share