System.OutOfMemoryException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I have the following problem on .net 1.1:

I reduced the problem to the following code:

byte[] ByteArrayOk=new byte[17000000];

ByteArrayOk=null;

byte[] ByteArrayOutOfMem=new byte[16773276]; // Exception here!!!

ByteArrayOutOfMem=null;

which throws a System.OutOfMemoryException.

On .net framework 2.0 everything works fine!
But I need a shortterm solution on 1.1!

Thanks for your help!

raise
 
raise said:
Hi!

I have the following problem on .net 1.1:

I reduced the problem to the following code:

byte[] ByteArrayOk=new byte[17000000];

ByteArrayOk=null;

byte[] ByteArrayOutOfMem=new byte[16773276]; // Exception here!!!

ByteArrayOutOfMem=null;

which throws a System.OutOfMemoryException.

On .net framework 2.0 everything works fine!
But I need a shortterm solution on 1.1!

Don't free the first array?

Force a GC collect between releasing the last reference to the first array
and allocating the second array?

-cd
 
There is no way to do this and be certain it's going to work.

You're right at the edge of the max memory you can allocate in an x86
process. You may get it to work sometimes by putting a full GC.Collect in
there between allocations, but nothing you do is going to make it work every
time.

It may work sometimes in .Net 2.0 (running on x86), but there are going to
be alot of times that it's not. You're right on the edge there.

Your only real solution is to migrate to .Net 2.0, and run under x64 or
IA64. Nothing else will work reliably.
 
Ops. I read your number wrong.

You're only allocating 17 megabytes, not 1.7 gigabytes as I assumed.

Do a full GC.Collect first, and if you still have failures, then you're
probably suffering from heap fragmentation. Are you doing any calls out to
Win32? Using Sockets? Files?

--
Chris Mullins


Chris Mullins said:
There is no way to do this and be certain it's going to work.

You're right at the edge of the max memory you can allocate in an x86
process. You may get it to work sometimes by putting a full GC.Collect in
there between allocations, but nothing you do is going to make it work
every time.

It may work sometimes in .Net 2.0 (running on x86), but there are going to
be alot of times that it's not. You're right on the edge there.

Your only real solution is to migrate to .Net 2.0, and run under x64 or
IA64. Nothing else will work reliably.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins


raise said:
Hi!

I have the following problem on .net 1.1:

I reduced the problem to the following code:

byte[] ByteArrayOk=new byte[17000000];

ByteArrayOk=null;

byte[] ByteArrayOutOfMem=new byte[16773276]; // Exception here!!!

ByteArrayOutOfMem=null;

which throws a System.OutOfMemoryException.

On .net framework 2.0 everything works fine!
But I need a shortterm solution on 1.1!

Thanks for your help!

raise
 
Back
Top