Garbage Collection Bug In .NET Framework!!!

B

Barry Anderberg

To see the bug for yourself, create a new C# Windows Forms
application.

Put a call to this function in your Form constructor:

private void OverflowLargeObjectHeap()
{
int[] largeArray;

largeArray = new int[1000000];

for (int i=0;i<=100;i++)
{
GC.Collect();

// previous reference is lost so int array should be garbage
collected - but it isn't!
largeArray = new int[largeArray.Length + 100000];
}
}


Run the program, and watch what happens. The garbage collector isn't
properly cleaning up these objects from the large object heap after
their reference count goes to zero!

That's a BIG BUG!
 
J

Jon Skeet [C# MVP]

Barry Anderberg said:
To see the bug for yourself, create a new C# Windows Forms
application.

Put a call to this function in your Form constructor:

private void OverflowLargeObjectHeap()
{
int[] largeArray;

largeArray = new int[1000000];

for (int i=0;i<=100;i++)
{
GC.Collect();

// previous reference is lost so int array should be garbage
collected - but it isn't!
largeArray = new int[largeArray.Length + 100000];
}
}

Run the program, and watch what happens. The garbage collector isn't
properly cleaning up these objects from the large object heap after
their reference count goes to zero!

That's a BIG BUG!

(I'm not sure why you're suggesting using a Windows Forms project here.
Why is everyone so hung up about making everything use Forms? This is
an ideal candidate for a console app.)

I'm not seeing the effect you presumably are. Here's my version of your
test app:

using System;

class Test
{
static void Main()
{
Console.WriteLine (GC.GetTotalMemory(true));
int[] largeArray;

largeArray = new int[1000000];

for (int i=0;i<=100;i++)
{
GC.Collect();

// previous reference is lost so int array should
// be garbage collected - but it isn't!
largeArray = new int[largeArray.Length + 100000];
}
Console.WriteLine (GC.GetTotalMemory(true));
}
}

Now, I get results of:

12064
19064

which certainly doesn't show the hundreds of megs of memory being lost
which you're implying. What results do you get?
 
D

Daniel O'Connell [C# MVP]

Barry Anderberg said:
To see the bug for yourself, create a new C# Windows Forms
application.

Put a call to this function in your Form constructor:

private void OverflowLargeObjectHeap()
{
int[] largeArray;

largeArray = new int[1000000];

for (int i=0;i<=100;i++)
{
GC.Collect();

// previous reference is lost so int array should be garbage
collected - but it isn't!
largeArray = new int[largeArray.Length + 100000];
}
}


Run the program, and watch what happens. The garbage collector isn't
properly cleaning up these objects from the large object heap after
their reference count goes to zero!

This sounds an awful lot like the Large Object Heap[1] bug in 1.0. This was
fixed in 1.1 I'm pretty sure(which should be why Jon isn't seeing it). For
these things please post the version of the framework you are using.

1. http://discuss.develop.com/archives/wa.exe?A2=ind0202A&L=DOTNET&P=R4086
 
B

Barry Anderberg

Jon,

Are you using the 1.0 Framework? This is not an issue in 1.1.

What I see is the program suck up over 400MB of memory when it should
consume 44MB of memory.

I ran the program on my home machine using 1.1 and it wasn't a
problem.

-Barry

Jon Skeet said:
Barry Anderberg said:
To see the bug for yourself, create a new C# Windows Forms
application.

Put a call to this function in your Form constructor:

private void OverflowLargeObjectHeap()
{
int[] largeArray;

largeArray = new int[1000000];

for (int i=0;i<=100;i++)
{
GC.Collect();

// previous reference is lost so int array should be garbage
collected - but it isn't!
largeArray = new int[largeArray.Length + 100000];
}
}

Run the program, and watch what happens. The garbage collector isn't
properly cleaning up these objects from the large object heap after
their reference count goes to zero!

That's a BIG BUG!

(I'm not sure why you're suggesting using a Windows Forms project here.
Why is everyone so hung up about making everything use Forms? This is
an ideal candidate for a console app.)

I'm not seeing the effect you presumably are. Here's my version of your
test app:

using System;

class Test
{
static void Main()
{
Console.WriteLine (GC.GetTotalMemory(true));
int[] largeArray;

largeArray = new int[1000000];

for (int i=0;i<=100;i++)
{
GC.Collect();

// previous reference is lost so int array should
// be garbage collected - but it isn't!
largeArray = new int[largeArray.Length + 100000];
}
Console.WriteLine (GC.GetTotalMemory(true));
}
}

Now, I get results of:

12064
19064

which certainly doesn't show the hundreds of megs of memory being lost
which you're implying. What results do you get?
 
J

Jon Skeet [C# MVP]

Barry Anderberg said:
Are you using the 1.0 Framework? This is not an issue in 1.1.

Ah, right. No, I'm using 1.1. I didn't realise you were using 1.0 -
there are known garbage collection issues with the large object heap in
1.0.
 
C

Chris Lyon [MSFT]

Hi Barry

Can you reproduce this with the latest v1.0 service pack? If so, it has definitely been fixed in the upcoming SP3.

Also keep in mind, if you compile your app in debug mode, the gc will be much lazier about collecting memory, so this app will indicate the memory is still hanging around. Try
compiling in retail mode.

Thanks
-Chris

--------------------
From: "Daniel O'Connell [C# MVP]" <[email protected]>
References: <[email protected]>
Subject: Re: Garbage Collection Bug In .NET Framework!!!
Date: Wed, 19 May 2004 04:44:35 -0500
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2096
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2096
X-RFC2646: Format=Flowed; Original
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: c-24-15-41-207.client.comcast.net 24.15.41.207
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.general:134549
X-Tomcat-NG: microsoft.public.dotnet.general


Barry Anderberg said:
To see the bug for yourself, create a new C# Windows Forms
application.

Put a call to this function in your Form constructor:

private void OverflowLargeObjectHeap()
{
int[] largeArray;

largeArray = new int[1000000];

for (int i=0;i<=100;i++)
{
GC.Collect();

// previous reference is lost so int array should be garbage
collected - but it isn't!
largeArray = new int[largeArray.Length + 100000];
}
}


Run the program, and watch what happens. The garbage collector isn't
properly cleaning up these objects from the large object heap after
their reference count goes to zero!

This sounds an awful lot like the Large Object Heap[1] bug in 1.0. This was
fixed in 1.1 I'm pretty sure(which should be why Jon isn't seeing it). For
these things please post the version of the framework you are using.

1. http://discuss.develop.com/archives/wa.exe?A2=ind0202A&L=DOTNET&P=R4086
That's a BIG BUG!


--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
 
P

PaulG

Jon Skeet said:
I'm not seeing the effect you presumably are. Here's my version of your
test app:
Console.WriteLine (GC.GetTotalMemory(true));

For what it's worth, I'm experiencing some major problems with the
garbage collector not freeing memory as well, and my objects aren't
very large.

Try running your code again, passing false instead of true, to
GetTotalMemory. I found through experimenting that
GetTotalMemory(true) does kick the GC into freeing my memory. But
nothing else does. It doesn't free on its own while the program is
running, and even explicit calls to Collect have no effect. Unless I
call GetTotalMemory(true), memory usage grows, until my machine
thrashes itself almost to a halt.

I'm running .NET 1.1.4322.

Paul
 
G

Guest

Hi Chris
Can you reproduce this with the latest v1.0 service pack?
If so, it has definitely been fixed in the upcoming SP3.

As I'm having a similar problem I would be very interested in knowing more about this SP - specially the release date as we will be delivering an update of our application in the immediate future.

In adition, can you confirm that the Large Object Heap problem has not ben resolved in any of the post SP2 roll-up packages?


Thanks,

Flemming S. Iversen
Software Architect
Maersk Data Defence
www.maerskdata-defence.dk
(e-mail address removed)
 

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