foreach (XmlNode xmlNd in lstForm)
{
if (xmlNd.Attributes.Item(4).Value.Trim() != "")
{
oBaseForm = (BaseForm)System.Activator.CreateInstance(Type.GetType(xmlNd.Attributes.Item(4).Value));
oBaseForm.FormType = xmlNd.Attributes.Item(0).Value;
oBaseForm.MenuID = xmlNd.Attributes.Item(2).Value;
oBaseForm.IsSystemForm = bool.Parse(xmlNd.Attributes.Item(3).Value);
oBaseForm.xmlCFile = xmlNd.Attributes.Item(5).Value;
oBaseForm.xmlEFile = xmlNd.Attributes.Item(6).Value;
oBaseForm.FormCount = 1; if (!htbForms.ContainsKey(oBaseForm.FormType))
{
htbForms.Add(oBaseForm.FormType, oBaseForm);
}
else
{
Message.MsgErrorInfo("FormConfigError");
return false;
}
}
}
我有这样一段程序,创建很多BaseForm子类的实例.我想在某个子类的实例不用时,释放掉.不知道如何操作? 希望高手们帮我一把,谢谢呀!
垃圾回收随时都可能跟进的,包括在模块关掉前。
public class BaseForm
{
private string Formtype ;
public BaseForm
{
}
public virtual void bItemClicked(ref SAPbouiCOM.ItemEvent pVal,
out Boolean BubbleEvent,SAPbouiCOM.Form oForm)
{
BubbleEvent = true;
}}
创建实例
public BaseForm oBaseForm ;
oBaseForm = System.Activator.CreateInstance(Type.GetType('unis.BaseForm'));
如果这时执行oBaseForm=null,
实例并没有被释放。用了Gc.Collect()。也没用。 如果我在整个程序中执行了10000次System.Activator.CreateInstance(Type.GetType('unis.BaseForm')),垃圾不是很多了呀?
小弟,自己随便学了点c#.net,还请各位高人指教。