Why Garbage Collection Fails?

Is there a way to see why an object is not being collected? I can see that the number of instances of a class is constantly climbing on the 'All Classes' tab but on the 'All Objects' tab it is only referenced once (as expected).

I have several classes that are essentially a data record class that gets queued, processed and disposed of. But despite not appearing to be referenced anymore by my program, they still don't get collected, even when forcing a garbage collection.

I am using C# in MSVS2008 and .NET Framework 3.5

Sample class as follows : -

private enum RequestType {APPEND, OVER_WRITE};
private class FileRequest
public string strData;
public RequestType reqType;

public FileRequest(string data, RequestType type)
strData = data;
reqType = type;


  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hello Sean,

    .NET's Garbage Collector will not free objects when other objects are holding a reference to them, not even if garbage collection is forced. If it behaved this way it would probably wreak havoc with your program.

    You can normally trace the reference up to the root object using ANTS Profiler's hierarchy tab, clicking on the referenced from until you see a yes in the root object column.

    Sorry to say, the method for fixing the problem is not clearly defined. It may involve invoking an object's Dispose() method, decrementing an event handler, or closing a network or database connection.

    Hopefully this helps you a bit...
Sign In or Register to comment.