1. In the past, the add method of list <t> was commonly used, so I didn't care much about it. It was often a problem.
Static list <Object> A = new list...
Addb void (){
Object B = new object;
A. Add (B );
}
B is a temporary variable. After the addb program is executed, object B is released. However, you can still access the value a [0.
I have read the msdn explanation of ADD.
"Before adding a new element, the capacity of list <(of <(T>)> is increased by automatically allocating an internal array and existing elements are copied to the new array. "
That is to say, when a executes add, it first applies for a piece of memory space and copies the content of B (memory copy ). Instead of storing the address of B in. List is not a linked list. Therefore, the elements in a are saved.
2. List <t> how to release it in time.
In wince programming, memory is limited, so we hope resources can be recycled by the garbage collector GC as soon as possible.
You can manually call
Staticclass. staticlist = NULL;
GC. Collect ();
Release resources in a timely manner.
3. dynamically add and use fonts in wince.
Wince API functions are required
Code
[Dllimport ("coredll", entrypoint = "addfontresource")]
Private Static extern int addfontresource ([IN, financialas (unmanagedtype. lpwstr)] string fontsource );
[Dllimport ("coredll", entrypoint = "sendmessage")]
Private Static extern int sendmessage (intptr hwnd, int MSG, intptr wparam, intptr lparam );
[Dllimport ("coredll", entrypoint = "removefontresource")]
Private Static extern int removefontresource ([IN, financialas (unmanagedtype. lpwstr)] string fontsource );
Run
Int installfont = addfontresource (@ "\ temp \ simsun. TTC ");
If (installfont! = 0)
{
Sendmessage (intptr) 0 xFFFF, 0x001d, intptr. Zero, intptr. Zero );
}
It must be released at the end; otherwise, memory leakage may occur.
Int removefont = removefontresource (@ "\ temp \ simsun. TTC ");
If (removefont! = 0 ){
Sendmessage (intptr) 0 xFFFF, 0x001d, intptr. Zero, intptr. Zero );
}
Sendmessage is used to notify all programs that the font has changed. VC # define wm_fontchange 0x001d;
Use the following program to view the fonts currently available
Installedfontcollection enumfonts = new installedfontcollection ();
Fontfamily [] fonts = enumfonts. Families;
Foreach (fontfamily font in fonts ){
MessageBox. Show (font. Name );
}