Qiuwei

Hi, there;
I am not quite clear about these cases, can anybody help this please

Suppose Utility.cs has all public static fields.

1. string mystring = Utility.MyStaticString +"anything";
  • Can "mystring" be collected
  • Can "anything" be collected
2.Utility.MyStaticString = string1+string2;
  • Can string1 and string2 be collected
3. Please have a look at this case:
MyClass
{
string _myString = Utility.MyStaticString + "something";
...
}

MyMainProgram
{
MyClass obj = new MyClass();
...
}
  • Can obj be collected
4. What is the general rule to create a static field in .NET
By the way, any doc/web site I can read about static field.


Cheers,








Re: .NET Compact Framework About GC

Ilya Tumanov

1. Yes and yes.

2. Yes and yes. But not the concatenated string which this code produces as it¡¯s assigned to a static field.

3. Yes.

4. You use static as required by your application. Generally if you need a value which is not attached to particular class instance you use static. Classic example is a static field which holds count of all instances of this class.






Re: .NET Compact Framework About GC

Qiuwei

Thank you very much.

It is very helpful.

Cheers,