dongyinglan8707 2016-11-15 01:24
浏览 18
已采纳

我是否需要明确停止报价已重新分配的股票行情?

I'm using time.Ticker to do some stuff at a regular interval. I want to be able to change the frequency that stuff happens at:

for {
        select {
        case <-ticker.C:
            //do stuff
        case t := <-newTicker:
            oldTicker := ticker
            ticker = t
            oldTicker.Stop()
        }
    }

Do I need that ticker cleanup to avoid a memory leak, or will reassigning ticker like

case ticker := <-newTicker:

be enough?

  • 写回答

1条回答 默认 最新

  • dpowhyh70416 2016-11-15 08:28
    关注

    As JimB mentioned as per time package GoDoc.

    Under time.NewTicker, the following is mentioned.

    Stop the ticker to release associated resources.

    Provided you run oldTimer.Stop(), oldTicker will get garbage collected after exiting the case statement as it's out of scope.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥40 matlab简单代码修改补充
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败
  • ¥15 数据结构中的数组地址问题
  • ¥15 maya的mel里,怎样先选择模型A,然后利用mel脚本自动选择有相同名字的模型B呢。
  • ¥15 Python题,根本不会啊
  • ¥15 会会信号与系统和python的来
  • ¥15 关于#python#的问题
  • ¥20 oracle RAC 怎么配置啊,配置
  • ¥15 excel 日常使用中出现问题