all groups > dotnet clr > april 2007 >
You're in the

dotnet clr

group:

GB.Collect() can be trusted?


RE: GB.Collect() can be trusted? Peter Ritchie [C# MVP]
4/19/2007 9:08:01 AM
dotnet clr: GC.Collect is documented as "Use this method to attempt to reclaim all memory
that is inaccessible. However, the Collect method does not guarantee that all
inaccessible memory is reclaimed".

I can't think of any reason why the GC won't collect all inaccessible memory.

WinDbg and SOS are a little more helpful at what you're describing.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


[quoted text, click to view]
Re: GB.Collect() can be trusted? Chris Mullins [MVP]
4/19/2007 10:27:18 AM
[quoted text, click to view]

The only thing that comes to mind is fragmentation.

GC.Collect typically does the collection and them performs a compaction.
When the heap is fragmented, that compaction doesn't work very well, and you
can end up without much "free" memory...

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

Re: GB.Collect() can be trusted? Peter Ritchie [C# MVP]
4/19/2007 10:38:05 AM
That shouln't cause a particular object to not be collected though.

My interpretation of "memory leak" could have been different than yours or
Ward's. Mine what that a particular object wasn't collected... I don't pay
attention to usable space as an indiciation of memory leaks. Due, as you
say, to fragmentation...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


[quoted text, click to view]
GB.Collect() can be trusted? Ward Bekker
4/19/2007 12:33:11 PM
Hi,

I'm wondering if the GC.Collect method really collects all objects
possible objects? Or is this still a "smart" process sometimes keeping
objects alive even if they can be garbage collected?

I need to know because I'm looking for memory leaks in an application.

It would be really helpful to be able to determine if an object after
manually invoking the GC.Collect is only kept alive because it still
being referenced by other alive objects in contrast to being alive
because the GC.Collect didn't found it necessary to collect the object,
even when asked explicitly.

Regards,

Re: GB.Collect() can be trusted? Chris Mullins [MVP]
4/19/2007 2:26:27 PM
I agree - this wouldn't at all cause something to not be collected.

The original poster should be able to use one of the existing tools
(Scitech's Memory Profiler, Red Gate's Memory Profiler, heck - even WinDbg
with SOS can do this), walk the root paths, and see why his object wasn't
collected. It should be pretty easy.

The tools have recently started getting so very good. Red Gate & SciTech now
have x64 support, SciTech can load in MiniDump files so you can do
post-crash memory analysis - it makes debugging so much easier than it used
to be.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

[quoted text, click to view]

Re: GB.Collect() can be trusted? Ward Bekker
4/20/2007 2:00:22 PM
Thanks guys for your help,

More discussion of this thread can be found here:
Re: GB.Collect() can be trusted? Serge Baltic
4/23/2007 5:05:33 PM
Hello,

[quoted text, click to view]

Maybe you should rather use a memory profiler, such as dotTrace, for example?
That way you'll clearly see the objects that are “leaked” and trace the references
that are preventing them from being reclaimed.

(H) Serge

Re: GB.Collect() can be trusted? sergeyudaltsov NO[at]SPAM yahoo.com
4/24/2007 5:00:39 AM
YourKit .NET profiler shows GC activity and has tools for memory leak
hunting
http://www.yourkit.com/dotnet/

GR,
Sergey
AddThis Social Bookmark Button