memory never been collected

W

www.dir

I am developing C# application that every 10 seconds refreshes TreeView
control. I am using 3 custom classes for renewing the TreeView control.

And It seems that I do not free some resources, so every 10 seconds the
memory used by my application is increasing ( I was monitoring that
from task manager ) I know that because of the way Garbage Collector
works, it is not recommended to trust the task manager so I downloaded
AQtime ( http://www.automatedqa.com/ ) and monitoring my application
with this software it turned out that every 10 seconds a new instance
of my custom classes are created, and they are not released. I've
tested the application for 5 minutes and I had 30 instances, and the
used memory was still growing up. This software have a function to
force the garbage collection, and I have tried it - the count dropped
to 7. I've forced the garbage collector again - the count was 1.
As far as I am informed how the GC is working isn't it supposed to
start every time it need new memory?
Actually I find this very strange. Can someone help?
Somewhere in Internet I read that it is not recommended to call the
Garbage Collector ( GC.Clollect() ). Can you tell me whether this is
true and if yes why.

Thanks.
 
M

Mattias Sjögren

As far as I am informed how the GC is working isn't it supposed to
start every time it need new memory?

Right. Unless those 30 instances take up significant amounts of memory
I wouldn't worry.

Somewhere in Internet I read that it is not recommended to call the
Garbage Collector ( GC.Clollect() ). Can you tell me whether this is
true and if yes why.

Because then you're trying to outsmart the garbage collector. It's
almost always best to just let it do what it does best and not
interfere.



Mattias
 
M

Mrinal Kamboj

Hi ,

That's true , GC definitely comes into the picture but our dude has a
"undeterministic" tag associated with it so , it doesn't bother itself
till there's a real shortage of memory and compaction is required for
new allocations - in simple words , however i am dead sure things are
much more complex than this .

Also , it's been suggested not to GC.collect explicitly until and unless
really required since , this will add to object retention ,as it places
your object in finalization queue , in first GC run , that means ready
for collection next time , so , even when it will ensure definite
garbage collection , it will happen in 2 cycles instead of normal one ,
where there was a chance to miss it if it had some references or was
reachable .

Mrinal
 
W

Willy Denoyette [MVP]

Mrinal Kamboj said:
Hi ,


Also , it's been suggested not to GC.collect explicitly until and unless
really required since , this will add to object retention ,as it places
your object in finalization queue , in first GC run , that means ready for
collection next time , so , even when it will ensure definite garbage
collection , it will happen in 2 cycles instead of normal one , where
there was a chance to miss it if it had some references or was reachable .
Note that this is only true for objects that have destructors, object that
don't have destructors never end on the finalization queue. The same is true
for objects implementing the Dispose pattern, provided Dispose() was called
before object "destruction".

Willy.
 

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

Similar Threads


Top