From fa0f3efab72f3a978415b5da5417f2a9eabdaf1b Mon Sep 17 00:00:00 2001 From: Nan Monnand Deng Date: Fri, 13 Jun 2014 14:02:26 -0400 Subject: [PATCH] fix the memory leak problem mentioned in #26 --- cadvisor.go | 1 + manager/container.go | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cadvisor.go b/cadvisor.go index 352fd794..931dc4b9 100644 --- a/cadvisor.go +++ b/cadvisor.go @@ -36,6 +36,7 @@ var argResetPeriod = flag.Duration("reset_period", 2*time.Hour, "period to reset func main() { flag.Parse() + // XXX(dengnan): Should we allow users to specify which sampler they want to use? container.SetStatsParameter(&container.StatsParameter{ Sampler: "uniform", diff --git a/manager/container.go b/manager/container.go index 59e1bdcd..3b0e3422 100644 --- a/manager/container.go +++ b/manager/container.go @@ -37,9 +37,9 @@ type containerStat struct { type containerInfo struct { info.ContainerReference Subcontainers []info.ContainerReference - Spec *info.ContainerSpec - Stats *list.List - StatsSummary *info.ContainerStatsPercentiles + Spec *info.ContainerSpec + Stats *list.List + StatsSummary *info.ContainerStatsPercentiles } type containerData struct { @@ -100,12 +100,14 @@ func NewContainerData(containerName string) (*containerData, error) { func (c *containerData) housekeeping() { // Housekeep every second. - for true { + ticker := time.NewTicker(1 * time.Second) + defer ticker.Stop() + for { select { case <-c.stop: // Stop housekeeping when signaled. return - case <-time.Tick(time.Second): + case <-ticker.C: start := time.Now() c.housekeepingTick()