Garbage collector in datagridview.

C

coco343

Hello,
I'm using a datagridview with an inner dropdownlist for a column.
The datasource for the gridview and the dropdrownlist is a object,
with inner collection for the dropdrownlist.

When i change the datasource of both and i clear the binding of the
gridview, i call GC.Collect(), to clear my local cache. But the object
is not collected, it seem there is still a reference to it, from the
dropdownlist ...

I didn't find any databinding clear, and setting datasource to
nothing, didn't change anything.

Any idea ?

Thanks

Decco
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Hello,
I'm using a datagridview with an inner dropdownlist for a column.
The datasource for the gridview and the dropdrownlist is a object,
with inner collection for the dropdrownlist.

When i change the datasource of both and i clear the binding of the
gridview, i call GC.Collect(), to clear my local cache. But the object
is not collected, it seem there is still a reference to it, from the
dropdownlist ...

I didn't find any databinding clear, and setting datasource to
nothing, didn't change anything.

Any idea ?

Thanks

Decco

Never call GC.Collect. (Unless you have a really good reason and know
exactly why you are doing it.)

Forcing a collection doesn't in any way guarantee that all collectable
objects are actually collected. How did you determine that the objects
were not collected, anyway?
 
C

coco343

Never call GC.Collect. (Unless you have a really good reason and know
exactly why you are doing it.)

Forcing a collection doesn't in any way guarantee that all collectable
objects are actually collected. How did you determine that the objects
were not collected, anyway?

--
Göran Andersson
_____http://www.guffa.com- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

I'm using a dictionnary of weakreference to those object, to make the
local cache. (it's to have less request to the DB).
So, time to time, i must clear the cache.
I call GC.collect, and after i delete from the dictonnary, the
weakreference where isAlive is false.
But i can see that they are still Alive, and the dictonnary is not
empty.

Also, when i remove the dropdown list, it work as expected, so i
deduce the dropdownlist have a reference to the object ...

do you have a better idea to make a local cache ?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

I'm using a dictionnary of weakreference to those object, to make the
local cache. (it's to have less request to the DB).
So, time to time, i must clear the cache.

Why do you believe that you have to clear the cache?

If you are using weak references to the objects, the objects will be
garbage collected if needed.
I call GC.collect, and after i delete from the dictonnary, the
weakreference where isAlive is false.
But i can see that they are still Alive, and the dictonnary is not
empty.

The WeakReference objects doesn't disappear just because the object that
it references is collected. The IsAlive property indicates whether the
object still exists or not. If it's false, then the object doesn't exist
any more.
 
C

coco343

Why do you believe that you have to clear the cache?

If you are using weak references to the objects, the objects will be
garbage collected if needed.


The WeakReference objects doesn't disappear just because the object that
it references is collected. The IsAlive property indicates whether the
object still exists or not. If it's false, then the object doesn't exist
any more.



--
Göran Andersson
_____http://www.guffa.com- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

The WeakReference objects doesn't disappear just because the object that
it references is collected. The IsAlive property indicates whether the
object still exists or not. If it's false, then the object doesn't exist
any more.

that's why, i check if the IsAlive is false. if it's false, i don't
need anymore the weakref in my dictionary, so i remove them.
But the IsAlive are still true, the object aren't collected. And this,
only when i use the combobox in the gridview.
Else, when i don't use de combobox, the object are collected as
expected, the isAlive go false, and i can remove the weakref from the
dictionnary.
 

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