0
以下是我的代码: 将静态log = null的Dispose方法导致内存泄漏吗?如果是,如何避免这一点,并释放静电日志资源?..设置其值= null时,是否会释放静态变量?
public class LogUtil:IDisposable
{
private StreamWriter logwriter;
private LogUtil(StreamWriter sw)
{
this.logwriter = sw;
}
public void Dispose()
{
if (log != null)
{
this.logwriter.Close();
this.logwriter.Dispose();
log = null;
}
}
private static LogUtil log = null;
public static LogUtil getTodayLog()
{
if (log == null)
{
String logfilePath = System.Environment.CurrentDirectory + String.Format("\\{0}{1}{2}.log", DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
StreamWriter sw = new StreamWriter(logfilePath, true, Encoding.UTF8);
log = new LogUtil(sw);
return log;
}
else
return log;
}
}