R
Rolf Welskes
Hello,
I have a problem with garbage collection.
An msdn example says generally the following:
I have a class TestCls.
With a Property MyProp.
Then normally I would write:
void MyFunc()
{
TestCls tc = new TestCls();
int u = tc.MyProp;
.... no further use of tc ....
}
The example says this would not work, because the gc could work (finalizer
called) before tc.MyProp has finished.
This is a catastroph.
The example says I had to write:
void MyFunc()
{
TestCls tc = new TestCls();
int u = tc.MyProp;
.... no further use of tc ....
gc.KeepAlive(tc);
}
Think about this, if you have many such objeckts and calls in a method.
Furthermore:
I have tested the example of the msdn: gc Class/ GcMethodes/KeepAlive
Methode
which is at
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref2/html/M_System_GC_KeepAlive_1_b4c5a2da.htm
in Msdn VS 2005.
I mean the FIRST example.
I have a computer with 2 cpus (intel dualcore), but the example does not
works as described.
So question is it reality?
Have I to use in this case (only manged code, no interop) the
KeepAlive-Method?
(I only mean this sample with pure dotnet, if I use interop the use of
KeepAlive is clear for me).
Thank you for any help.
Rolf Welskes
I have a problem with garbage collection.
An msdn example says generally the following:
I have a class TestCls.
With a Property MyProp.
Then normally I would write:
void MyFunc()
{
TestCls tc = new TestCls();
int u = tc.MyProp;
.... no further use of tc ....
}
The example says this would not work, because the gc could work (finalizer
called) before tc.MyProp has finished.
This is a catastroph.
The example says I had to write:
void MyFunc()
{
TestCls tc = new TestCls();
int u = tc.MyProp;
.... no further use of tc ....
gc.KeepAlive(tc);
}
Think about this, if you have many such objeckts and calls in a method.
Furthermore:
I have tested the example of the msdn: gc Class/ GcMethodes/KeepAlive
Methode
which is at
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref2/html/M_System_GC_KeepAlive_1_b4c5a2da.htm
in Msdn VS 2005.
I mean the FIRST example.
I have a computer with 2 cpus (intel dualcore), but the example does not
works as described.
So question is it reality?
Have I to use in this case (only manged code, no interop) the
KeepAlive-Method?
(I only mean this sample with pure dotnet, if I use interop the use of
KeepAlive is clear for me).
Thank you for any help.
Rolf Welskes