473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Memory leaks in managed code?

Kev

I've been trying to understand the article "Identifying Memory Leaks in
the Common Language Runtime" listed on http://support.microsoft.com/?id=318263

It says "The garbage collector can
collect and free the memory but never returns it to the operating system.
This occurs when the garbage collector cannot move the objects that are
still in use to one portion of the memory and free the rest."

How can this happen? I know the basics of garbage collection and memory
deallocation, but I don't understand how and why the GC would move around
free blocks and objects. Is the only goal consolidation of free space?

Also, what's the difference betweeen point #2 ("Memory is disposed of but
never collected, because a reference to the object is still active.") and
point #4 ("Poor memory management can result when many large objects are
declared and never permitted to leave scope.")?

And finally, are there any good resources to help understand the inner
workings on the CLR garbage collector? (I'm a .NET beginner!) Does the CLR GC use
"pinning", or does it use something else?

Thanks.

Kevin

Nov 17 '05 #1
9 1347
> How can this happen? I know the basics of garbage collection and memory
deallocation, but I don't understand how and why the GC would move
around free blocks and objects. Is the only goal consolidation of free
space?
You allocate memory from the OS in blocks. The entire block has to be
free before you can return it to the operating system. So, it makes sense
to free up block by consolidating memory.
Also, what's the difference betweeen point #2 ("Memory is disposed of
but never collected, because a reference to the object is still
active.") and point #4 ("Poor memory management can result when many
large objects are declared and never permitted to leave scope.")?
Point #2 is for example, when two objects have a reference to eachother.
They will never be collected.

Point #4 is something different entirely, like a static variable in a
function which references a huge object.
And finally, are there any good resources to help understand the inner
workings on the CLR garbage collector? (I'm a .NET beginner!) Does the
CLR GC use "pinning", or does it use something else?

The book from Jeffrey Richter has a nice explanation. See
http://safari.oreilly.com.

Greetings,
Wessel
Nov 17 '05 #2
Which specific book by Jeffrey Richter are you referring to?

Thanks,
Brett

Nov 17 '05 #3
"Applied Microsoft .NET Framework Programming"
chapter 19, "Automatic Memory Management (Garbage Collection)"

Greetings,
Wessel

On Mon, 18 Jul 2005 21:33:57 +0200, brett <ac*****@cygen.com> wrote:
Which specific book by Jeffrey Richter are you referring to?

Thanks,
Brett


Nov 17 '05 #4
Inline

Willy.

"Wessel Troost" <no*****@like.the.sun> wrote in message
news:op.st4hvfcvf3yrl7@asbel...
How can this happen? I know the basics of garbage collection and memory
deallocation, but I don't understand how and why the GC would move
around free blocks and objects. Is the only goal consolidation of free
space?
You allocate memory from the OS in blocks. The entire block has to be
free before you can return it to the operating system. So, it makes sense
to free up block by consolidating memory.


These blocks are called segments and the CLR uses segment sizes of 32 MB for
the workstation GC and 64MB for the server GC.
But keep in mind that the CLR never returns the initial (2) segments
allocated, only additional segments are ever returned to the OS.

Also, what's the difference betweeen point #2 ("Memory is disposed of
but never collected, because a reference to the object is still
active.") and point #4 ("Poor memory management can result when many
large objects are declared and never permitted to leave scope.")?

Point #2 is for example, when two objects have a reference to eachother.
They will never be collected.


This is not true, cycles are correctly collected by the GC.
Point #4 is something different entirely, like a static variable in a
function which references a huge object.
And finally, are there any good resources to help understand the inner
workings on the CLR garbage collector? (I'm a .NET beginner!) Does the
CLR GC use "pinning", or does it use something else?

The book from Jeffrey Richter has a nice explanation. See
http://safari.oreilly.com.

Greetings,
Wessel

Nov 17 '05 #5

Kev" <kr*@user.doma.in> schrieb im Newsbeitrag
news:Pi*******************************@conquest.OC F.Berkeley.EDU...
<snip>

I've been trying to understand the article "Identifying Memory Leaks in
the Common Language Runtime" listed on
http://support.microsoft.com/?id=318263
</snip>

<snip> Also, what's the difference betweeen point #2 ("Memory is disposed of but
never collected, because a reference to the object is still active.") and
point #4 ("Poor memory management can result when many large objects are
declared and never permitted to leave scope.")?

</snip>

These four points in the article are about memory leak in general, not
specific for .NET.

Christof
Nov 17 '05 #6
>> Point #2 is for example, when two objects have a reference to eachother.
They will never be collected.

This is not true, cycles are correctly collected by the GC.


Could you elaborate on that?

Greetings,
Wessel
Nov 17 '05 #7

"Wessel Troost" <no*****@like.the.sun> wrote in message
news:op.st5muunqf3yrl7@asbel...
Point #2 is for example, when two objects have a reference to eachother.
They will never be collected.

This is not true, cycles are correctly collected by the GC.


Could you elaborate on that?

Greetings,
Wessel


Sure, but I guess you better start reading this:
http://msdn.microsoft.com/msdnmag/is...I/default.aspx
especially the Garbage Collection algorithm chapter explains how the GC
tracks the reachable objects and builds an object graph starting from a
"root". Objects that are no longer "rooted", be it directly or indirectly,
are considered garbage and will be collected.

Willy.



Nov 17 '05 #8
> Sure, but I guess you better start reading this:
http://msdn.microsoft.com/msdnmag/is...I/default.aspx
Thanks for the pointer, nice article, looks like the chapter from "Applied
Microsoft .NET Framework Programming" tho :-)
especially the Garbage Collection algorithm chapter explains how the GC
tracks the reachable objects and builds an object graph starting from a
"root". Objects that are no longer "rooted", be it directly or
indirectly,
are considered garbage and will be collected.

Agreed, the example I gave would be collected. I was back thinking in COM
terms, when each object had a reference counter.

Greetings,
Wessel
Nov 17 '05 #9
Inline
Willy.

"Wessel Troost" <no*****@like.the.sun> wrote in message
news:op.st5ylrkpf3yrl7@asbel...
Sure, but I guess you better start reading this:
http://msdn.microsoft.com/msdnmag/is...I/default.aspx


Thanks for the pointer, nice article, looks like the chapter from "Applied
Microsoft .NET Framework Programming" tho :-)


Yep, same author isn't it?
Note that while I agree that it's a nice article, it's also a bit outdated,
so not all what's written in there is still correct. More detailed/accurate
articles are written by members of the CLR team, like the highly recommended
reading here:
http://blogs.msdn.com/maoni/default.aspx

especially the Garbage Collection algorithm chapter explains how the GC
tracks the reachable objects and builds an object graph starting from a
"root". Objects that are no longer "rooted", be it directly or
indirectly,
are considered garbage and will be collected.

Agreed, the example I gave would be collected. I was back thinking in COM
terms, when each object had a reference counter.

Greetings,
Wessel

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
2
by: ASP.Confused | last post by:
How would I go about detecting a memory leak? My web hosting provider has our site set up to only have a root "bin" folder for .NET apps, and I would like to be able to watch how much memory is...
2
by: James Hunter Ross | last post by:
Friends, I've been watching or W3WP process size (using Task Manager), and it grows and grows when using our application. I am the only one on our server. I'll end my session, either through...
17
by: David Schwartz | last post by:
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app definitely has some memory leaks, so I did a simple test to see if it was my app or something about VB.NET. I created...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
30
by: MAG1301 | last post by:
I've detected memory leaks in our huge .NET 1.1 C# application but couldn't localize them directly. So I've reduced the code to the following console application: using System; using System.IO;...
4
by: PL | last post by:
Hi everyone, I was surprised to see memory leaks in our application when it crashed today. Basically, the code is written in C#, but with c# and C++ DLLS; its the latter (managed extensions) that...
2
by: Trev | last post by:
Is the file "Microsoft Visual Studio .NET 2003\VC7\INCLUDE\crtdbg.h" (specifically, the new operators) used in any way, shape or form in C# ? I am involved in writing an app that uses managed C++...
3
by: not_a_commie | last post by:
The CLR won't garbage collect until it needs to. You should see the memory usage climb for some time before stabilizing. Can you change your declaration to use the 'out' keyword rather than a 'ref'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.