System.OutOfMemoryException

F

fniles

We are using VB.NET 2008.
The machine where the program is running at is a 16 core machine which
has 4 Gig of RAM.
When the program tried to create another thread, it says "Exception of
type 'System.OutOfMemoryException' was thrown."
When I go to Task Manager and check the Processes, "Mem Usage" for
this program is 557,268 and "VM Size" is 1,341,300 and "Threads" is
816.
These are the information from Accessories - System Tools - System
Information:
Available physical memory is 2.41 Gb.
Total virtual memory is 5.82 Gb.
Available virtual memory is 3.41 Gb.

Why 'System.OutOfMemoryException' was thrown when there are still
available physical and virtual memory ?

Thank you.
 
T

Tom Shelton

fniles presented the following explanation :
We are using VB.NET 2008.
The machine where the program is running at is a 16 core machine which
has 4 Gig of RAM.
When the program tried to create another thread, it says "Exception of
type 'System.OutOfMemoryException' was thrown."
When I go to Task Manager and check the Processes, "Mem Usage" for
this program is 557,268 and "VM Size" is 1,341,300 and "Threads" is
816.
These are the information from Accessories - System Tools - System
Information:
Available physical memory is 2.41 Gb.
Total virtual memory is 5.82 Gb.
Available virtual memory is 3.41 Gb.

Why 'System.OutOfMemoryException' was thrown when there are still
available physical and virtual memory ?

Thank you.

816 threads? That's probably your problem... Each application is
given a fixed amount of stack space - this is static, so it won't be in
virtual memory, etc. Each thread you create uses up a fixed amount of
that stack space (I seem to remember about 2MB). So, basically, once
that is used up - you can't allocate anymore threads.
 
F

fniles

Thank you for your quick reply.
Each time a new client connects to the program it creates a thread, so
if there are 800 clients, there will be 800 threads.
These are the codes to do it:
Dim oThread As Threading.Thread

oThread = New Threading.Thread(AddressOf oSession.ThreadMain)
oThread.SetApartmentState(ApartmentState.STA)
oThread.Name = CLng(nSession)
oThread.Start()

What is the maximum number of threads an application can have ?
What is the best way to hanle this situation ? Create a thread pool ?
 
C

Cor

32bit of 64 bit, AFAIK is the max addressable memory a program can use in
32bit is 2GB

Take a look at this page where your problem in my idea is specified
http://msdn.microsoft.com/en-us/library/aa366778(VS.85).aspx

Cor

"fniles" wrote in message

We are using VB.NET 2008.
The machine where the program is running at is a 16 core machine which
has 4 Gig of RAM.
When the program tried to create another thread, it says "Exception of
type 'System.OutOfMemoryException' was thrown."
When I go to Task Manager and check the Processes, "Mem Usage" for
this program is 557,268 and "VM Size" is 1,341,300 and "Threads" is
816.
These are the information from Accessories - System Tools - System
Information:
Available physical memory is 2.41 Gb.
Total virtual memory is 5.82 Gb.
Available virtual memory is 3.41 Gb.

Why 'System.OutOfMemoryException' was thrown when there are still
available physical and virtual memory ?

Thank you.
 
F

fniles

Thank you.
32bit of 64 bit
Did you mean is it a 32 bit or 64 bit machine ?
It is a 32 bit server machine.
AFAIK is the max addressable memory a program can use in 32bit is 2GB
What is AFAIK ?
The server machine where the program is running is a Windows Server
2003 with Service Pack 2 (SP2), Standard Edition.
According to the article that you referred to, the limits on physical
memory for Windows Server 2003 with SP2 is 4 GB (Limit on X86).
Did you mean even though the limits on physical memory on that machine
is 4 GB, but the max addressable memory a program can use in that
machine is only 2GB ?
Is this based on that article that says this info ? Does it mean I can
increase it to 3 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4GT ?
Memory type
User-mode virtual address space for each 32-bit process

Limit in on X86
2 GB
Up to 3 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4GT

In the project property (in VB.NET), under "Compile" - "Advanced
Compile Options" - "Target CPU" is x86.
 
C

Cor

I've also no system admin experience with this, but what I've always read is
in my idea your conclusion correct.

But I think the technet forums are a much better place for this question.

Http://technet.microsoft.com/forums

In fact I'm parroting what I've always heard (read).

Cor


"fniles" wrote in message

Thank you.
32bit of 64 bit
Did you mean is it a 32 bit or 64 bit machine ?
It is a 32 bit server machine.
AFAIK is the max addressable memory a program can use in 32bit is 2GB
What is AFAIK ?
The server machine where the program is running is a Windows Server
2003 with Service Pack 2 (SP2), Standard Edition.
According to the article that you referred to, the limits on physical
memory for Windows Server 2003 with SP2 is 4 GB (Limit on X86).
Did you mean even though the limits on physical memory on that machine
is 4 GB, but the max addressable memory a program can use in that
machine is only 2GB ?
Is this based on that article that says this info ? Does it mean I can
increase it to 3 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4GT ?
Memory type
User-mode virtual address space for each 32-bit process

Limit in on X86
2 GB
Up to 3 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4GT

In the project property (in VB.NET), under "Compile" - "Advanced
Compile Options" - "Target CPU" is x86.
 

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