System.Timers.Timer持续大量消耗内存的原因是什么?
- 内容介绍
- 文章标签
- 相关推荐
本文共计126个文字,预计阅读时间需要1分钟。
csharpusing System;using System.Collections.Generic;using System.Text;using System.Timers;
public class MemoryEater{ private Timer timer;
public MemoryEater() { timer=new Timer(1000); // 设置定时器间隔为1秒 timer.Elapsed +=Timer_Elapsed; // 绑定定时器事件 timer.AutoReset=true; // 设置为自动重置 timer.Start(); // 启动定时器 }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { byte[] buffer=new byte[1024 * 1024]; // 创建1MB的内存缓冲区 buffer=null; // 释放缓冲区 }
public static void Main() { new MemoryEater(); }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Timers;usingSyste System.Timers.Timer不断地吃掉内存???(内附完整源码) usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Timers;usingSyste本文共计126个文字,预计阅读时间需要1分钟。
csharpusing System;using System.Collections.Generic;using System.Text;using System.Timers;
public class MemoryEater{ private Timer timer;
public MemoryEater() { timer=new Timer(1000); // 设置定时器间隔为1秒 timer.Elapsed +=Timer_Elapsed; // 绑定定时器事件 timer.AutoReset=true; // 设置为自动重置 timer.Start(); // 启动定时器 }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { byte[] buffer=new byte[1024 * 1024]; // 创建1MB的内存缓冲区 buffer=null; // 释放缓冲区 }
public static void Main() { new MemoryEater(); }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Timers;usingSyste System.Timers.Timer不断地吃掉内存???(内附完整源码) usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Timers;usingSyste
